author
71Instructables1,327,115Views343CommentsAustralia

Tell us about yourself!

Achievements

100+ Comments Earned a bronze medal
1M+ Views Earned a silver medal
Age of Aquariums Contest
Contest Winner Third Prize in the Age of Aquariums Contest
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    The power requirements come in short bursts during Transmit.No problems with the TxPower setting I am aware of.

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    What the trick that made it work for you?

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Try changing the port on the bridge to 2000 and then try to connect to it. There are other 'local' IP ranges other then 10.1.1.1 like 192.168.x.x but you should be able to configure the Navionics app the connect to 10.1.1.1OR try the UDP connection

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Make sure the RS232 baud rate is correct. Connect the debug output TX to a TTL to USB cable to see what is arriving at the bridge.I am not a sailor so perhaps someone else here can help with OPENCPN, but check the connection setting for IP and data port match what is set in the bridge config. NOTE: the IP address is fixed in the bridge so the OPENCPN must be changed to match that. The port numbers also need to match.

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Update 9th August 2021 – Fixed links to pfodESP8266BufferedClient library

    Update 9th August 2021 – Fixed links to pfodESP8266BufferedClient library

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    I am not not familiar with that app. Perhaps someone else can comment.The project does not care what the RS232 input is it just takes lines of data and retransmitts them via UDP/TCP. If your app can either i) connect to a UDP server or ii) connect to a server via TCP then I would expect you would get some data.

    View Instructable »
  • Taming Arduino Strings -- How to Avoid Memory Issues

    Update 9th July 2021 - Added link to fixed versions of Arduino Strings files. Normally not needed.

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Here is another video with some more details.It seems that the nRF52 can be unlocked by a full erase and the Glicher used in the video is only to allow you to read back the software from a locked nRF52 so would no normally be used for just programming.(I have not actually tested any of this yet)

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Yes, If anyone gets the build process working for creating a cheaper version, can they post it here.

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Sorry I have not used the ESP8266 as a DHCP server. A quick web search did not show up any simple example code, but suggests it is supported by the SDK

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    try manually setting an IP for your computer say 10.1.1.100

    View Instructable »
    • Room Heater Control Via BLE Temperature Sensor
      126 views
      2 favorites
      0 comments
  • Simple Multitasking in Arduino on Any Board

    Short answer, by default the Arduino loop() runs on core1 and the wifi/ble runs on core 0Long answersIn ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\config\sdkconfig.hyou will find#define CONFIG_ARDUINO_RUNNING_CORE 1and#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1Then in ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\main.cpp xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);which creates the Arduino 'loopTask' on core 1Then in ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\esp32\esp_wifi.h#if CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1#define WIFI_TASK_CORE_ID 1and further down .wifi_task_core_id = WIFI_TASK_CORE_IDWhich later passed to wifiLowLevelInit( ) which …

    see more »

    Short answer, by default the Arduino loop() runs on core1 and the wifi/ble runs on core 0Long answersIn ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\config\sdkconfig.hyou will find#define CONFIG_ARDUINO_RUNNING_CORE 1and#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1Then in ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\main.cpp xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);which creates the Arduino 'loopTask' on core 1Then in ..\Arduino15\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\esp32\esp_wifi.h#if CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1#define WIFI_TASK_CORE_ID 1and further down .wifi_task_core_id = WIFI_TASK_CORE_IDWhich later passed to wifiLowLevelInit( ) which calls esp_wifi_init( )

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    I am not familiar with that type of connection. However I assume the VHF radio takes an RS232 connection. If that is the case then you need to connect both this unit AND the radio to the TX line from the NEMA/AIS unit so that is feeds both. Try just connecting the VHF first and see that that works and then run the TX/GND to this unit as well.

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    To un-install loopTimer and millisDelay, (after installing the SafeString library) just delete their directories in the libraries directory, i.e. delete the directories../Arduino/libraries/loopTimer and .../Arduino/libaries/millisDelay

    Yes, they are in the SafeString library, to un-install loopTimer and millisDelay, just delete their directories in the libraries, i.e. delete.../libraries/loopTimer and .../libaries/millisDelay

    View Instructable »
  • drmpf's instructable LoRa Controlled Garage Door's weekly stats:
    • LoRa Controlled Garage Door
      77 views
      3 favorites
      0 comments
  • Arduino Strings for Beginners, the SafeString Alternative

    22 Jan 2021: add section on Using SafeStrings for class variables

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    What is the debug output showing? Are you talking TCP server or UDP broadcast?The sketch will hang in setup until it connects to the router. So if you can see data being transmitted, that suggests the ESP got a connection to the router. You could try rebooting the router, or testing on a different router, e.g. your home network. You could also try using the Fing android app to scan for devices connected on the network.Finally ignoring all that. Can you connect to the IP the ESP has setup from your computer telnet and see the data?

    View Instructable »
  • Garage Door Opener With Position - ESP2866

    Update 19th Jan 2021: There is an LoRa Controlled Garage Door version of this project.

    View Instructable »
  • Quick Start for Real World Text I/O Applications

    12th January 2021: Revised to use SafeStringReader and BufferedInput

    View Instructable »
  • Arduino Strings for Beginners, the SafeString Alternative

    Update 8th January 2021: V3.0.1 added SafeStringReader.end() and support for SAMD boards and minor fix to readUntilToken Update 6th January 2021: V3.0.0 added SafeStringReader, BufferedInput, loopTimer, millisDelay

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    Update 6th Jan 2021 – loopTimer class now part of the SafeString library (V3+) install it from Arduino Library manager or from its zip file

    View Instructable »
  • Coding Timers and Delays in Arduino

    6th Jan 2020 update: The millisDelay class is now part of the SafeString library V3+. Download SafeString from the Arduino Library manager or from its zip file

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Update 9th January 2021 – Addedextra TCP connection and reuse last connection if more clientsconnectThanks to lammensh for helping with this.

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    I have a test program for you to try. Please PM me your email or contact me via pfod.com.au at support

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Try replacing the if (!foundSlot) { } block with this code. Let me know if it solves your issueif (!foundSlot) { // drop some other client?? perhaps have half closed connection problem if (debugPtr) { debugPtr->println("No free slots for this client close last one."); } tcpServerClients[MAX_SRV_CLIENTS - 1].stop(); tcpServerClients[MAX_SRV_CLIENTS - 1] = tcpServer.available(); tcpServerClients[MAX_SRV_CLIENTS - 1].setNoDelay(true); // does not do much if anything bufferedClients[MAX_SRV_CLIENTS - 1]->stop(); // clean up bufferedClients[MAX_SRV_CLIENTS - 1]->connect(& (tcpServerClients[MAX_SRV_CLIENTS - 1])); #ifdef CONNECTION_MESSAGES if (debugPtr) { debugPtr->print("New client replacing previous: "); debugPtr->println(i); } #endif …

    see more »

    Try replacing the if (!foundSlot) { } block with this code. Let me know if it solves your issueif (!foundSlot) { // drop some other client?? perhaps have half closed connection problem if (debugPtr) { debugPtr->println("No free slots for this client close last one."); } tcpServerClients[MAX_SRV_CLIENTS - 1].stop(); tcpServerClients[MAX_SRV_CLIENTS - 1] = tcpServer.available(); tcpServerClients[MAX_SRV_CLIENTS - 1].setNoDelay(true); // does not do much if anything bufferedClients[MAX_SRV_CLIENTS - 1]->stop(); // clean up bufferedClients[MAX_SRV_CLIENTS - 1]->connect(& (tcpServerClients[MAX_SRV_CLIENTS - 1])); #ifdef CONNECTION_MESSAGES if (debugPtr) { debugPtr->print("New client replacing previous: "); debugPtr->println(i); } #endif // WiFiClient tcpServerClient = tcpServer.available(); // tcpServerClient.stop(); }

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Hi, Currently when all the connections are full it just rejects the next connection. This may a problem if your connects do no shut down cleanly. In other projects (pfodApp) I send keep-alive msgs and clear the connection once they stop coming, but that is not possible in general, because your client may not send any messages at all. Depends on the client.Can you connect the debug output and see what messages turn up there.One possibility would be to close one of the existing connections when there is no room so the latest connect can always connect.

    View Instructable »
    • Arduino Serial I/O for the Real World
      1,709 views
      9 favorites
      0 comments
  • Arduino Strings for Beginners, the SafeString Alternative

    Update 13th December 2020: SafeString V2.0.5 Added SafeStringStream, BufferedOutput, readUntilToken() and clarified stoken() V nextToken(), renamed nl() to newline() to avoid ESP32 conflict

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    Check out the no config version which should do what you need.

    Check out the no config version which should do what you need.

    12th Dec 2020 -- added no config version for use with existing networks that already have a router (access point). In that version all the config is pre-programmed.

    View Instructable »
  • How to Use Strings in Arduino for Beginners

    Update 12th November 2020: Updated instructable for SafeString V2.0.0 added wrapping of char* and char[] in a SafeString and added typing shortcuts for the createSafeString... macros. (See Wrapping existing char arrays). Added an OBD data processing example.

    View Instructable »
  • A Cheaper ESP8266 WiFi Shield for Arduino and Other Micros

    Update: 29th Oct 2020Tested with ESP8266 board library V2.7.4 –works

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Hi, https://www.forward.com.au/pfod/BLE/LowPower/NanoR...covers setting pins for a new board.For the programmer settings check out the boards.txt that comes with the Adafruit Feather and base yours on that. In general I would not recommend this board for Very Low Power because it has a lot of extras:- A Battery charger, USB/TTL chip, power monitoring resistors, all of which draw extra current. For very low current you want the bare minimum of hardware.I have not used the jlink programmer myself so I am not much help on that butlooks like Adafruit Feather nRF52 Bluefruit LE [nRF52832] already uses the S132 softdevice so you may not need to program it.

    View Instructable »
  • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

    The simple way is to hard code your wlan SSID and PW into the code when you build it.And at the same time set all the other parameters your need and then skip the webpage startup.Private msg me if you need help with this.

    View Instructable »
    • Stepper Speed Control Menu Driven for Arduino
      154 views
      4 favorites
      0 comments
    • Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use
      52 views
      1 favorites
      0 comments
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Ok back to tried and true debugging method.Remove come until is starts working, see Debugging Low Power above for checking if the loop is waking up.Then put code back in a little bit at a time to isolate the problem code.E.g. leave out the SPI code and LCD hardware and support code, but put in the calculation/handling code that works to prepare the data.Add back the SPI begin() end() but without the hardware and don't send any data. Then send some dummy data (without the LCD hardware/library)Keep adding stuff back in in small steps to find the problem.

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    I have not used the SPI bus in the low power / sleep mode.Suggest you stop / shutdown the SPI bus completely between accessing the LCD

    View Instructable »
  • Coding Timers and Delays in Arduino

    Hi cedrix00,You can have three separate millisdelays, each with their own time setting, and control the calls accordingly.See Step 4 in https://www.instructables.com/Simple-Multi-task...for an example of this.If you are still having trouble, message me directly.

    View Instructable »
  • Coding Timers and Delays in Arduino

    :-( Good catch. Thanks for that.Fixed that now. Website was correct https://www.forward.com.au/pfod/ArduinoProgramming...

    View Instructable »
    • Arduino NANO 33 Made Easy BLE, Sense and IoT
      49 views
      0 favorites
      0 comments
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Hi,>>4. I generate .Hex file, send to the phone, and I am able to upload as "application" with the nRF connect App. It also asks for a .dat file, but it can upload th .hex fileSorry cannot help with this as I have never tried to PROGRAM the nRF51 via an Android mobile (OTA over the air). As that requires a special program to be running on the BLE chip and adds another level of complexity I can do without. As shown in this instructable, all my programming is done direct to an nRF52 (not an nRF51) chip via a programmer.Suggest give up on trying to program from your Android mobile and purchase some nRF52 chips (which have more memory) and try programming as described above.

    View Instructable »
  • Arduino String Manipulation Using Minimal Ram

    There is now a SafeString Arduino library available in the library manager that allows you to strictly limit the amount of memory your 'strings' use.see How to Use Strings in Arduino for BeginnersSafeString solves the problems of Arduino strings. SafeString never causes the sketch to reboot, never fragments the heap and includes detailed error checking and debugging messages

    View Instructable »
  • How to Use Strings in Arduino for Beginners

    Thanks to Va_Tech_EE, SafeString is now available to be installed via the Arduino Library Manager

    View Instructable »
  • How to Use Strings in Arduino for Beginners

    No just on my website (which is much older then github)Full source code is there in the ziphttps://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html

    No just on my website (which has been around much longer then github)Full source code is there in the ziphttps://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.htmlFeel free to re-host it on GitHub. Just include a link and acknowledgement to the webpage above.

    View Instructable »
    • Arduino String Processing for Beginners
      90 views
      1 favorites
      0 comments
  • Large Stepper Motor Control A4988

    Nice intro to stepper motors, but the code is not very useful. Using delay() is evil as it blocks the rest of the sketch from running.The problem with the example sketch is that it does not let you control the stepper motor speed or position or enter commands to set the position or speed while the motor is running.Simple Multitasking in Arduinohttps://www.instructables.com/Simple-Multi-task... has an example sketch using AccelStepper library that runs the stepper and still leaves the sketch free to do other tasksArduino String Processing for Beginnershttps://www.instructables.com/Arduino-String-Pr...has an example sketch that shows you how to you can processes user commands while still running the rest of the sketch at maximum speed.Combining these two instructables with your great intro …

    see more »

    Nice intro to stepper motors, but the code is not very useful. Using delay() is evil as it blocks the rest of the sketch from running.The problem with the example sketch is that it does not let you control the stepper motor speed or position or enter commands to set the position or speed while the motor is running.Simple Multitasking in Arduinohttps://www.instructables.com/Simple-Multi-task... has an example sketch using AccelStepper library that runs the stepper and still leaves the sketch free to do other tasksArduino String Processing for Beginnershttps://www.instructables.com/Arduino-String-Pr...has an example sketch that shows you how to you can processes user commands while still running the rest of the sketch at maximum speed.Combining these two instructables with your great intro to stepper motors will give you a stepper motor controller that can be controlled on the fly by the user or other external inputs

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    Thanks. Keep an eye out for the SafeStrings tutorial I am working on at the moment.

    View Instructable »
    • Simple Arduino Libraries for Beginners
      160 views
      1 favorites
      0 comments
  • Coding Timers and Delays in Arduino

    millisDelay certainly does not block, but whatever you are doing in the justFinished() might block or elsewhere in the code, could be blocking. SD card access can block. Also Serial.print can blockTry adding a loopTimer() to get a better idea of what delays there are.from Simple Multitasking in Arduino on Any Boardhttps://www.instructables.com/Simple-Multi-task...also see that instructable for non-blocking Serial I/O

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    Would you like to private message me with some sample code?

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Sorry no, only one connection at a time, but you are correct you can set up more then one connection and 'switch' between them by disconnecting and choosing another connection

    View Instructable »
  • Simple WiFi to BLE (Bluetooth Low Energy) Bridge

    Sure, it should be possible, but I have not do it myself.You could start with nRF Connect android apphttps://play.google.com/store/apps/details?id=no.n... and https://github.com/NordicSemiconductor/Android-nRF-Connect and use it to scan for your devices and then find out which services and characteristics they use and relay those.

    Well BLE is a mess. Every different device/service has its own characteristics so you would need to have special code to handle and repeat each one. I have not checked, but I suspect that the smart watches and lights etc define their own custom services so you would first need to discover what those were and then connect receive and re-transmit them.So in short not easy to do.

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    sounds good, msg me and we can take this off-line until it is fixed

    Looks like you are deeper in this than I needed to be. As you have probably already discovered, this project setup (compile/link) assumes there is a softdevice pre-loaded. If you load another hex that does not need a softdevice it may/will overwrite the exiting pre-loaded softdevice and so you will need to re-load the softdevice again when going back to this projects build process.Since you are using OpenOCD for debugging, how about putting together a short tutorial on using OpenOCD in debug mode to single step Arduino sketches?

    If you are not using either Particle Debugger or BlackMagic programmer, I cannot be of much help as those are the only ones I have experience with.The support for the other programmers was supplied by sandeepmistry so perhaps he can help you.Not sure what you mean by 'manually' flash. Arduino produces a hex file so you could just compile/download with not board attached and then find hex file that Arduino produced and manually flash it.

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    I think you are saying that you can flash a simple blink example. Can you flash that from an Arduino sketch?Are you first flashing the softdevice?I have not tried using ST-Link JTAG programmer or the Sparkfun board only the BlackMagic and Particle Programmer and the Redbead Nano V2, the SkyLab and GT832E_01 boards. If you are still having problems I suggest you start by following the instructable exactly using the Particle Debugger and one of the boards mentioned and get that working. Then try changing one part, e.g. start with changing the programmer and see that you can get that working. Then finally change the board. Note the Sparkfun board has different Arduino pin mappings from any of the other boards so you may have to create a new board for it See part 3 of this set of 3 ins…

    see more »

    I think you are saying that you can flash a simple blink example. Can you flash that from an Arduino sketch?Are you first flashing the softdevice?I have not tried using ST-Link JTAG programmer or the Sparkfun board only the BlackMagic and Particle Programmer and the Redbead Nano V2, the SkyLab and GT832E_01 boards. If you are still having problems I suggest you start by following the instructable exactly using the Particle Debugger and one of the boards mentioned and get that working. Then try changing one part, e.g. start with changing the programmer and see that you can get that working. Then finally change the board. Note the Sparkfun board has different Arduino pin mappings from any of the other boards so you may have to create a new board for it See part 3 of this set of 3 instructables.Looking at the Sparkfun schematic, programming is via TP1/TP2 and gnd, and the LED is on P_07 which in the Nano board pin mapping is called D8 in Arduino. Also in the NanoV2 board definition the LED_BUILTIN is set to 13 (D13 == P_011) and so will not flash the sparkfin led. Also on the NanoV2 tx/rx is P_29/P_30 while the SparkFun board uses P_27/P-26 You will need to define a new board definition for the SparkFun board.When you get that far start the TX/RX so you can debug the sketch.

    See my fuller reply, but for programming via SWDIO and SWDCLK see the bottom of https://learn.sparkfun.com/tutorials/nrf52832-breakout-board-hookup-guide

    View Instructable »
  • Custom BLE – No Programming Required

    Update 9th January 2020 – Add note for installing RFduino support now that the company website is gone

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    I can think of two problems, i) Sparkfun is using the sandeepmistry code base ii) Sparkfun has a boot loader installed on the chipeither or both of these could be stopping sleep from working.This instructable uses a modified and expanded version of sandeepmistry's code base and does not use a bootloader program on the chip.Be aware that if you follow these instructable you will a) need a real programmer as described aboveb) loose the convenience of Sparkfuns programming methodc) need to add support for this board to code used in this project, seehttps://www.forward.com.au/pfod/BLE/LowPower/NanoR...or https://www.instructables.com/Easy-Very-Low-Pow...

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    Connect a uart Blink_lp_timer.ino outputs print each time it wakes up, so check it only wakes up as shown above.

    The important output is loop() woke up at .. what does that say?

    View Instructable »
  • Very Low Power BLE Made Easy With Arduino -- Part 1

    two things come to mind.i) the UART draws mAs if started, even if nothing is connectedii) the the loop is not actually stopped. try the Blink_lp_debug.ino sketch (above) and see how long your loop is asleep(and the current drain with the UART running.)

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    Update 21st Nov 2019 - Added comparison examples for Arduino_FreeRTOS and frt compared to Simple Multi-tasking in Arduino

    View Instructable »
  • Simple Multitasking in Arduino on Any Board

    You seem to have the right idea.Well, in these cases you often need to turn the code inside out.That is bring the low level calls up to the top level and use a 'state' variable to keep track of where you are up to.Multitasking is about doing a little bit of a lot of things in sequence so that is appears a lot of things are happening at the same time.Handling the Avoidance will get messy so ideally you would put all the code in its own files Avoidance.cpp and Advoidance.h files in the same directory as your robot sketch .ino file.Here I will just assume all the code is in the main .ino sketch and all the variables are globals.copy this code the the IDE and reformat it.// Create some states to keep track of what Avoidance is doing// this would be a good place to use C enums// but for simpli…

    see more »

    You seem to have the right idea.Well, in these cases you often need to turn the code inside out.That is bring the low level calls up to the top level and use a 'state' variable to keep track of where you are up to.Multitasking is about doing a little bit of a lot of things in sequence so that is appears a lot of things are happening at the same time.Handling the Avoidance will get messy so ideally you would put all the code in its own files Avoidance.cpp and Advoidance.h files in the same directory as your robot sketch .ino file.Here I will just assume all the code is in the main .ino sketch and all the variables are globals.copy this code the the IDE and reformat it.// Create some states to keep track of what Avoidance is doing// this would be a good place to use C enums// but for simplicity/clarity, I am using the equivalent ints// the possible statesconst int AvoidanceIdle = 0;const int AvoidanceStart = 1;const int AvoidanceHaveResult = 2;const int AvoidanceRight = 3;const int AvoidanceFront = 4;const int AvoidanceLeft = 5;int AvoidanceState = AvoidanceIdle; // state variable initially idlemillisDelay servoMovementDelay;unsigned long SERVO_MOVEMENT_DELAY_MS = 600;void startAvoidance() { // set the start state if (AvoidanceState != AvoidanceIdle) { return; // already running } // else AvoidanceState == AvoidanceStart;}void startServoMove(int angle_to_look) { ServoEyes.write (angle_to_look); // start servo servoMovementDelay.start(SERVO_MOVEMENT_DELAY_MS); // start delay to tell us when it is finished // if you remember the last angle of the servo you can use that // to reduce the delay needed here based on angle to move}int getRange() { int range = eyes.Ranging(CM); // this call takes average of 20ms // see if you can change library to start call and come back // here later to get results // would need another AvoidanceState number to keep track of this return range;}int calculateNewDirection() { // ... return newDirection;}void goInNewDirection() { // change direction}void doAvoidanceCycle() { if (AvoidanceState == AvoidanceIdle) { return; // nothing to do return quickly } // else what are we up to // you could use a switch statement here particularly if using enums // but if else works as well if (AvoidanceState == AvoidanceStart) { // start finding range Front AvoidanceState = AvoidanceFront; startServoMove(C_Fangle); // start servo return; // nothing to do until servo get there } else if (AvoidanceState == AvoidanceFront) { if (servoMovementDelay.justFinished()) { rangeFront = getRange(); // this call takes average of 20ms // try next direction AvoidanceState = AvoidanceLeft; startServoMove(C_Langle); // start servo return; // nothing to do until servo get there } else { return; // still waiting for servo } } else if (AvoidanceState == AvoidanceLeft) { if (servoMovementDelay.justFinished()) { rangeLeft = getRange(); // this call takes average of 20ms // try next direction AvoidanceState = AvoidanceRight; startServoMove(C_Rangle); // start servo // if you remember the last angle of the servo you can use that // to reduce the delay needed here based on angle to move return; // nothing to do until servo get there } else { return; // still waiting for servo } } else if (AvoidanceState == AvoidanceRight) { if (servoMovementDelay.justFinished()) { rangeRight = getRange(); // this call takes average of 20ms newDirection = calculateNewDirection(); AvoidanceState = AvoidanceHaveResult; return; // main loop picks up newDirection and resets state to Idle } else { return; // still waiting for servo } } // else should not get here!!}//The main loop() would bevoid loop() { doAvoidanceCycle(); // call this every loop to check on millisDelay if (AvoidanceState == AvoidanceHaveResult) { // last call got new result // pick up new direction newDirection = newDirection; AvoidanceState = AvoidanceIdle; // go back to idle goInNewDirection(); } if (stuck) { // need to start avoidance again startAvoidance(); }}

    View Instructable »
  • Coding Timers and Delays in Arduino

    That is off topic here, email or msg me.

    I think you wanted to vary the delays so perhapsdelay(i*1000) instead.Delays are evil, but you won't notice that until you try and do something else as well as turn the leds on and off.

    View Instructable »
  • Coding Timers and Delays in Arduino

    There a couple of ways to do this. One uses just one millisDelay and keeps track of the relay state On/Off. A simplier approach is to use two millisDelays, one for the On and one for Off.Copy and paste the following code into Arduino and reformat it.// // flash led on Uno -- 6sec on and 30sec off using millisDelay#include <millisDelay.h>const int Led_pin = 13; millisDelay LedOnDelay;const unsigned long LED_ON_DELAY_MS = 6*1000; // 6 x 1000mS = 6secmillisDelay LedOffDelay;const unsigned long LED_OFF_DELAY_MS = 30*1000; // 30 x 1000mS = 30secvoid setup() { // put your setup code here, to run once: pinMode(Led_pin, OUTPUT); // set led output // note some relay boards are active HIGH and some active LOW // start with led ON digitalWrite(Led_pin, HIGH); // turn led On LedOnDel…

    see more »

    There a couple of ways to do this. One uses just one millisDelay and keeps track of the relay state On/Off. A simplier approach is to use two millisDelays, one for the On and one for Off.Copy and paste the following code into Arduino and reformat it.// // flash led on Uno -- 6sec on and 30sec off using millisDelay#include <millisDelay.h>const int Led_pin = 13; millisDelay LedOnDelay;const unsigned long LED_ON_DELAY_MS = 6*1000; // 6 x 1000mS = 6secmillisDelay LedOffDelay;const unsigned long LED_OFF_DELAY_MS = 30*1000; // 30 x 1000mS = 30secvoid setup() { // put your setup code here, to run once: pinMode(Led_pin, OUTPUT); // set led output // note some relay boards are active HIGH and some active LOW // start with led ON digitalWrite(Led_pin, HIGH); // turn led On LedOnDelay.start(LED_ON_DELAY_MS); // start delay}void loop() { // put your main code here, to run repeatedly: // check which timer has just finished if (LedOnDelay.justFinished()) { // turn led off and start offDelay digitalWrite(Led_pin, LOW); // turn led Off LedOffDelay.start(LED_OFF_DELAY_MS); } if (LedOffDelay.justFinished()) { // turn led on and start onDelay digitalWrite(Led_pin, HIGH); // turn led On LedOnDelay.start(LED_ON_DELAY_MS); } // other code here runs every loop}

    View Instructable »
  • Simple Multi-tasking in Arduino on Any Board

    Unfortunately your definition of multi-tasking is not accurate, you only need one core. see https://en.wikipedia.org/wiki/Computer_multitaskin..."Multitasking does not require parallel execution of multiple tasks at exactly the same time."The time management needs a deep knowledge of the microcontroller and its interrupts.The aim of this instructable was to avoid having a deep knowledge and to avoid completely using interrupts. The loopTime is used here to gives you the insight you need to develop a practical, useful program.As the title says this is 'simple' multi-tasking which avoids the complexities and board limitations of an RTOS system.

    Updated Supplies to include full list of software/libraries used in this instructable.

    View Instructable »
    • Simple Multi-tasking in Arduino on Any Board
      2,271 views
      11 favorites
      10 comments