Arduino thinkering

Arduino sketch experiancesPosted by Jan Tue, September 17, 2013 15:14:29In my previous post I stated I had to plug the yun in and out a couple of times on windows to get it to work. I didn't go into the details and I guess I should. So here I go.

I plugged in the yun and then started to download the arduino ide. Because I had plugged in the yun Windows wanted to install drivers.I opted to keep the driver installation window open until the arduino IDE installation was done because I need 1.5.4 installed for the yun drivers. I started the Arduino IDE installation as soon as it had downloaded.The installation halted at some point (I mean there was no more progress) which made me suspect that there was a conflict with the driver installation window being open. I opted to close the driver installation window. This means I canceled the windows new hardware installation.At this point the Arduino IDE installation progressed and finished a while later.To restart the driver installation of the yun I had to unplug the yun and replug.This restarted the found new hardware and installed the yun driver. I use yun driver in contrast to the yun bootloader driver. Just like the leonardo there are 2 com ports. In contrast to the leonardo a cold start of the yun does not activate the yun bootloader com port and as such the cold start does not install the yun bootloader driver.So when I wanted to upload my sketch the yun is reset and windows finds new hardware and wants to install the yun bootloader drivers.Not really aware of what was going on I selected to cancel the driver installation. I don't exactly remember what avr dude did at that time but I decided to unplug the yun to get back to normal behavior.Then I tried to upload again. Again I got a "new hardware found" and this time I decided to install the drivers. However avrdude didn't take this good as well. So after the driver installation I had to unplug the yun again to get back to normal.But then all was fine. In the yun guide at "http://arduino.cc/en/Guide/ArduinoYun#toc11" it states that the drivers should be installed but apparently in my case they were not. I'm not blaming anyone I just noticed they were not.The yun doc also states that the bootloader is started when pressing the reset button next to the ethernet connection. I could not try whether this works as I already installed the drivers.

In my previous post I also noted that minicom package was not available for the yun. However it is available. After selecting "update list" from the web interface I could install minicom.

2 yuns at the same time.Todays first challenge is to get the 2 yuns working at the same time.Eager to connect 2 yuns I start looking for a usb cable which I know I have. After looking for a long time I come across a mobile phone charger and I think: "He; this should do".So I power the yun with a mobile phone charger with mini USB. Remove all network connections from my system. Connect to the yun access point. and go to arduino.local. And it all works :-). After configuring the yun and reconnecting to my network I can access my yun with [myYunName].local. No connection problems and 2 com IP ports for the 2 yuns in the arduino IDE.I upload blinkwithout delay with a 5 second interval. It all magically works. This is the first Arduino I upload a sketch to which I never connected to a PC.Great work Arduino team :-)Connect an arduino mega to the yun.The second challenge is to connect an extra arduino to the yun. This is what i would call advanced usage.I took a duemilenove that has the uno bootloader for the first trial. (Read the duemilenove was lying next to me.)I connected it to the usb port of the yun and it powered up. So far so good.However dmesg reveils there is no com port associated with the arduino.[ 2325.260000] usb 1-1.1: new full-speed USB device number 5 using ehci-platform[ 2325.390000] usb 1-1.1: New USB device found, idVendor=0403, idProduct=6001[ 2325.390000] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3[ 2325.400000] usb 1-1.1: Product: FT232R USB UART[ 2325.400000] usb 1-1.1: Manufacturer: FTDI[ 2325.400000] usb 1-1.1: SerialNumber: A9007TX5

Trying to add a udev rule shows there is no udev folder in etc. So I installed the udev package (I used the web interface).Reconnecting the duemilenove and dmesg gives the same result.I created the file /etc/udev/rules.d/46-arduino.rules with following content (as described on the playground http://playground.arduino.cc//Linux/All)BUS=="usb", SYSFS{idVendor}=="1b4f", SYSFS{idProduct}=="9204", RUN+="/sbin/modprobe cdc_acm"BUS=="usb", SYSFS{idVendor}=="1b4f", SYSFS{idProduct}=="9204", RUN+="/bin/sh -c 'echo 0x1b4f 0x9204 > /sys/bus/usb/drivers/cdc_acm/new_id'" i disconnect and reconnect the duemilenove but nothing changes.I check the file /sys/bus/usb/drivers/cdc_acm/new_id and see it does not exist.even the folder cdc_acm does not exist. When I try to create it I get root@testyun:/etc/udev/rules.d# mkdir /sys/bus/usb/drivers/cdc_acmmkdir: can't create directory '/sys/bus/usb/drivers/cdc_acm': No such file or directory

Arduino sketch experiancesPosted by Jan Tue, September 17, 2013 01:05:49Today my yuns arrived. It is late but I want to get it a feel of it. So this will be a short first impression.

I downloaded and installed Arduino IDE 1.5.4 on my system beforehand so I start with plugging in the yun and .... no com port.OK; I never got the leonardo to work on my linux (redhat 6.4 ) so I can't blame the yun for that.Switching to windows XP virtual machine means downloading the 1.5.4 (again). I picked the uninstallable package.During the download I can read up from http://arduino.cc/en/Guide/ArduinoYun

I read that starting the yun for the first time makes it work like a wireless access-point. So I try this; I could not connect the first time. The second time It worked. Once connected nothing happens. What url to use when I fire up a browser?The description (till now?) didn't show a url or ip adress. running ifconfig in a terminal (ipconfig for windows people) showed my ipadress. Changing the last number to 1 and we can point the browser to the yun using http://192.168.240.1.

And there; I am requested to enter a password. I don't have a clue.More reading to be done :-( (Advice to arduino team: move the connection stuff more to the top of the article)And more reading reveals the url should be http://arduino.local but the ip is fine as well. The password is arduino (why didn't I guess this?).

The yun needs a really long time after I pressed login.......Which is normal as I disconnected the yun as the installation on my windows VM seemed to be blocked (and it did continue after unplugging) :-(

So plugging the yun back in; reconnected to the yun wireless interface.Configured the yun and hurray!!! I can access the yun remotely :-)After pressing configure there is an advanced configuration that is powered by luci. This means LUA is running on the yun . I have some LUA scripts so this is good news for me.

In the advanced configuration I can see that avrdude is installed :-) and there is still 7.14MB free. This together with the sd card makes a whole lot of storage. It looks like yun will meet my expectations :-)Looking through the packages I see that minicom is not one of the installed packages and also not in the available list. I'm used to running minicom (a serial monitor) on openwrt but that package is not available. There is probably something else.

Lets try to connect to the yun in linux over the network (overcoming that Leonardo is not working on my linux)But this one fails.The port is visible on my windows VM though.After unplugging the yun a couple of times trying to get the 2 drivers properly installed I can upload using the local com port on my windows xp vm. Uploading through the networks works immediately. Looking at the yun forum at arduino.cc I see that UDP remote port 5353 is needed. Adding this rule to my firewall on my Linux system makes I can upload to the yun remotely from my Linux system.

The first impressions are really good. I say : Very well done Arduino team.Tomorrow I want to try2 yuns at the same timeConnect an arduino mega to a yunUpload my robot scripts and make it workLets hope it all works.

Arduino sketch experiancesPosted by Jan Wed, September 11, 2013 20:37:35In the previous article I talked about how to get sentences over the serial line to arduino with the aim to control a Arduino sketch via the internet.If we want a sketch to control I need a sketch. (I know you are eager to get on the internet but we have to do this step by step. Bear with me)

I took the sample sketch "Blink without delay" made a c++ class for it and made a sketch "may way" (read with loop and setup methods).(OK; I modded quite a bit but it all started from the blink without delay and I added functionality to have a different on than off time.)

Then I extended the Serial string example we used before with a blinking led.

//The setup function is called once at startup of the sketchvoid setup(){ Serial.begin(9600); led13.setup(); mySerialReader.setup();}

// The loop function is called in an endless loopvoid loop(){ mySerialReader.loop(); led13.loop(); if (mySerialReader.messageReceived()) { Serial.println("You have send a message to Arduino."); Serial.println("And the message is:"); Serial.println(mySerialReader.getMessage()); }}

Lets look at the important parts:BlinkLed led13(LED_BUILTIN,500,2000);States the led is connected to pin LED_BUILTIN (13 on most arduinos) and is 500 millis on and 2000 millis off.led13.setup();Is to initialize the class. Andled13.loop();Makes sure the led blinks.If you want more leds blinking just add more leds to your Arduino and add more classes, setups and loops. You can use a different timing for each led.

If you download the BlinkLed library from github you can compile and upload the sketch to your Arduino.

Now that we have a sketch to change values; we can finally think about changing values. With this sketch we want to be able to change the on and the off time of the blinking led via the serial monitor. But we also want to be able to see the status, know the pin. In other words all the variables of the class must be visible.Remember I talked about "Kind of memory dump". What we need to do is tell Arduino what the kind of memory dump looks like. We do this by creating a new class that is derived from BlinkLed and from SerialDataInterface.SerialDataInterface is a helper class that allows you to easily create the "kind of memory dump" for a class.

NUMFields = 5 states there are 5 fields I want in the "kind of memory dump". We are talking about integers, floats, strings ...NUMChildren = 0; states there are nu children. Children are object derived from SerialDataInterface.The rest of the private section is always the same is is used to correctly allocate memory.MyBlinkLed(const char* name,uint8_t ledPin,uint32_t onInterval ,uint32_t offInterval);Is exactly the same asBlinkLed(uint8_t ledPin,uint32_t onInterval ,uint32_t offInterval);Except for I added a name we can use in the serial monitor to reference this particular instance of the class.

This is some hocuspocus code that links the variables to the names of the 5 fields and to the activities you can do with them.The first line states that the string "myOnInterval" refers to the variable myOnInterval. MOD_WRITE|MOD_SAVE states that this variable can be changed by the SET command and MOD_SAVE states that the current value can be saved in EEPROM with the "SAVE" command.If we assume that name is "led" we can change the value of myOnInterval by sending the following string followed by CR to Arduino.SET led.myOnInterval=3456If we want to save this value so that next time Arduino starts working it will use this value we sendSAVE

The next 4 lines are doing the same for the other fields. Note that if you see lots of garbage in the serial moniotor you probably made a mistake here or NUMFields is wrong.

The last 4 lines are always the same when the class doesn't have children.

Where are we?We have a class that is able to read line by line from the serial monitor.We have a class that does what we want to do BlinkLed.We have a class that describes the "kind of memory dump" of BlinkLed.What we now need is a class that handles the serial monitor line by line and links it to the memory dump.This class is called SerialCommunicator.

//The setup function is called once at startup of the sketchvoid setup(){ Serial.begin(9600); led13.setup(); mySerialCommunicator.setup(&led13);}

// The loop function is called in an endless loopvoid loop(){ mySerialCommunicator.loop(); led13.loop();}

leds go over it line by lineconst char * mySketchName="ssrDemo Part 2";The SerialCommunicator needs a name for the program. this is just a display name.SerialCommunicator mySerialCommunicator(A5);This line replaces SerialStringReader mySerialReader;. With this code you need to connect pin A5 to reset if you want Arduino to reset when you send "RESET".MyBlinkLed led13("BuildInLed",LED_BUILTIN,500,2000);Replaces BlinkLed led13(LED_BUILTIN,500,2000);. So we added a name for reference in the serial monitor.The next difference is mySerialCommunicator.setup(&led13);This used to bemySerialReader.setup();As there is only one object in the "kind of memory dump" we simply pass this object. Note that his object can have children. Therefore there you can always create 1 object corresponding to the "kind of memory dump".And finally I deleted the echoing of the serial monitor.

If you downloaded the libraries, compiled the sketch and uploaded the sketch. You will see ..... that the led is not blinking....open a serial monitor and send the SET command.SET will show you all the variables that you can change in the command format.On my board this givesSET Admin.ResetCount=10SET Admin.logLevel=255SET Admin.RestartDelay=65535SET Admin.DelaybetweenLogs=65535SET BuildInLed.myOnInterval=4294967295SET BuildInLed.myOffInterval=4294967295As you can see BuildInLed.myOnInterval is a huge number. This explains why trhe led is not blinking.Set it to 2000milis with the following commandSET BuildInLed.myOnInterval=2000and also give a nice off interval with SET BuildInLed.myOffInterval=5000

Now the led is blinking again.You are probably thinking "We have set the intervals in the code. How did they get lost?"Well we have indeed set the values but we also have overwritten them later on.Remember we said that myOnInterval was MOD_WRITE|MOD_SAVE.MOD_WRITE means we enable the SET command on this fields.MOD_SAVE means we can save the value to EEPROM. It is no use saving the value when you do not read it.So when we called mySerialCommunicator.setup(&led13); The value was replaced by what is in EEPROM and that will be different based on the history of the board.Send the SAVE command and reset the board.Run the SET command again and the values should be OK now.

The Admin stuff is the memory dump of mySerialCommunicator. ResetCount tells you how many times the board has been reset.logLevel is a flag telling wether log is on or off. Bit 0 is used for serial monitor logging. So in my case serial monitoring is on.RestartDelay is a delay time before restart is triggered. I put this on 850DelaybetweenLogs tells how many times the serial monitor will get a logging. I mostly start with 1000 meaning every second the serial monitor will get a line with the "kind of memory dump" in a csv line style.To know what is what dump the header with the LOG HEADER commandLOG VALUE;15;255;65535;65535;730022;0;789;4294967295;4294967295;0;0;13;>>Send to /dev/ttyUSB0: "LOG HEADER"<<LOG HEADER;Admin.ResetCount;Admin.logLevel;Admin.RestartDelay;Admin.DelaybetweenLogs;Admin.LoopCounter;Admin.AveragebetweenLoops;Admin.MaxbetweenLoops;BuildInLed.myOnInterval;BuildInLed.myOffInterval;BuildInLed.myLedState;BuildInLed.myPreviousMillis;BuildInLed.myLedPin;

If you understood all this you are up to the next episode: "controlling the serial monitor with an openwrt"

Arduino sketch experiancesPosted by Jan Mon, September 09, 2013 03:06:22I have been working some years now on building my own lawn mowing robot. I know you can buy a lawnmower robot in the shop but after intense market search I didn't find anything suiting my needs.The main problem is that the inhabitants of my garden like to make piles which makes for a very unflat surface. After some trials to make it flat I gave up and started designing Marvin.Marvin is a 4by4 frontmower lawnmower robot. He is planned to become fully autonomous but currently still needs to be brought to his charging station. Marvin is currently taking care of around 3000 square meters. But is planned to be able to handle 5000 and probably even more.you can read more on Marvin in this post on the arduino forum. http://forum.arduino.cc/index.php?topic=186329.0

But here I want to focus a bit on the "communication part"Having a robot running in your garden is cool. But when you are developing the robot you want to be able to connect to the robot wit the serial monitor and upload a new sketch without having to run around with a laptop and a USB cable.There are several options to do this. I have opted to hack a linksys router install openwrt and upload from there.Wait .... did I say openwrt??? Isn't that what yun will be running? Would this way be compatible with the yun? Well likely but it probably will need some tuning.To explain this all I have to tell you a long story so you can understand how it works. I want to tell you why you would listen to the whole story first.

What do you get to learn?How can I upload a sketch remotely (I mean over the internet if needed)How can I change parameters of my sketch easily (I mean over the internet if needed)How can I reboot my sketch remotely (I mean over the internet if needed)How can I program parameters in progmem (I mean over the internet if needed)First things first. What do I mean with (I mean over the internet if needed).The entrance point to your arduino becomes the system running openwrt (or any linux for that part). Accessing that system from your local network is easy. Accessing it from the internet requires some more work and it may have a financial impact (a other subscription wih your network provider). This set of articles is not going into this area as I assume you only need to access your arduino from your local network.

What do you need?1) A arduino.2) A machine able to run openwrt (or linux) that has a serial port and an Ethernet connection. If you want to go wireless this needs to be a wireless connection and that rules the pi out (unless you go for pi with wireless dongle) but any wireless router that has been hacked by the openwrt community should do.I have used a linksys WRT54GL but that one is kind of short on "disk space" I hope the yun (which is in the same price range) will do better.3) A router your machine running openwrt can connect to. (That is just like the pc you are using is connected to your local network)

That is all the hardware you need.

Look at this (slightly outdated drawing) to get the picture.Note that the yun promises to be 1 and 2 together.Also note that I did not succeed to hack the router with a sd card which left me with very little space which again should be solved by the yun.

What needs to be done to setup the same for your system?1) Adapt your Arduino code so it is compliant.2) Adapt the Arduino hardware so it is compliant.3) Install and configure the linux scripts and software.

The first one is needed so that serial commands send to arduino are processed properly. For instance sending "RESET" should make the arduino reset. Some code is needed on Arduino to do so.The second is needed because a RESET must be a hardware reset. The easiest is to connect a pin to the reset pin of the arduino. That finishes the hardware modifications The third one is needed to send commands to arduino via the network and to make the output of arduino available on the network. For instance you want to install avrdude to upload your sketch and minicom to have a remote serial monitor.

Step 2 and 3 are easy for a user. Step 1 requires a good understanding on what is going on with Arduino and is what major bulk of this set of articles is about.

Lets end this blog with and start the explanation with :"Sending line commands over the serial monitor"The big bulk of examples of serial communication towards the arduino are character based commands. This is easy as each character is self containing. You do not need to know what was send before or will be send after each character.For instance when you send 's' arduino starts. When you send 'p' arduino pauses.But what if you send "Fast play". Arduino would understand start and then pause. To be able to give long readable commands like "SET led.pwm=20" we need a line interpreter and not a character interpreter. The first thing you need for a line interpreter is to agree on the "end of the line character sequence". As you can see in the Arduino serial monitor you have several options to add to the characters you send. Namely "no line ending", "carriage return", "newline" and "both NL & CR".If you want to do line interpretation "no line ending" is not an option (though default in arduino) you need a special string to mark the end of the line. "carriage return", "newline" and "both NL & CR" are all commonly used (One is popular in linux land the other in windowsland).Therefore the basis of all the above promises starts with a class that does the line interpretation for you. This class handles "carriage return", "newline" and "both NL & CR" seamlessly so you do not need to bother. This class can be downloaded from github at https://github.com/jantje/libraries/tree/master/SerialStringReader

The example looks like

#include "SerialStringReader.h"SerialStringReader mySerialReader;

//The setup function is called once at startup of the sketchvoid setup(){ Serial.begin(9600); mySerialReader.setup();}

// The loop function is called in an endless loopvoid loop(){ mySerialReader.loop(); if (mySerialReader.messageReceived()) { Serial.println("You have send a message to Arduino."); Serial.println("And the message is:"); Serial.println(mySerialReader.getMessage()); }}

I'll go into some detail as it contains some techniques you will see coming back.First of all I use C++ classes. this allows me to declare the variableSerialStringReader mySerialReader;and then call methods on it.mySerialReader.setup();mySerialReader.loop();All the classes have a setup() and loop(). setup() should be called in the main setup and loop in the main loop.I do part of the initialization in the constructor and part in the setup. (No need to worry f you do not understand this)All the repetitive action are in loop.Upload this example to a Arduino and open the serial monitor. As you will see processing line by line in Arduino was never so easy.

1) multiple configurations (within the same board.txt file; so no uno to due )2) Full Teensy support (that is inclusive Teensy3; extra installation needed)3) bug fix for Due4) turning on/off "all warnings" (per configuration)5) Flag to set a "alternative size command" (the one used in V1 of the plugin) per configuration.6) Fields to add commands to the C and C++ command line 7)
More technically: Most of the data is now saved in the configuration
(environment variables). This makes it possible for the end user to
overwrite any configuration by modifying the environment settings of the
configuration.

To run Teensy download and unzip (make sure the files have execute rights) this fileor better use this tar version Peter has done a nice writeup here.

eclipse pluginPosted by Jan Fri, May 24, 2013 15:37:41I nearly finished V2.1 and I'm looking for alfa testers to do testing beginning of June.All the changes are really small so I expect no real issues.

What is new and what are alfa testers supposed to test1) multiple configurations (within the same board.txt file; so no uno to due )2) Full Teensy support (that is inclusive Teensy3; extra installation needed)3) bug fix for Due4) turning on/off "all warnings" (per configuration)5) Flag to set a "alternative size command" (the one used in V1 of the plugin) per configuration.6) Fields to add commands to the C and C++ command line 7) More technically: Most of the data is now saved in the configuration (environment variables). This makes it possible for the end user to overwrite any configuration by modifying the environment settings of the configuration.

If you want to volunteer for testing: please send me an e-mail (eclipse@baeyens.it) specifying the OS(es) you want to test in and the hardware you can/want to test with.Previous experience with the plugin is recommended.

Best regardsJantje

PS There is still a indexing problem with Teensy3 Paul is looking at. This makes "serial+ctrl space" not to work. Having 2 configurations (one for Teensy2 and 1 for Teensy3) is a work around.

eclipse pluginPosted by Jan Sat, March 23, 2013 15:45:08V2 beta of the Arduino eclipse plugin is available.What does it bring?1) It works exactly the same on Windows Linux and Mac.2) Super simple to install and configure.3) Has the Arduino buttons so you can easily find the Arduino commands4) Has an Arduino menu for amongst others importing the libraries5) Has the Serial monitor supporting 4 serial connections6) Has improved indexer functionality7) Has support for Arduino IDE 1.5.2 (that is inclusive due)8) Has the Arduino project and your sketch in the same eclipse projectWhat is downside?1) You need eclipse juno. Older versions are not supported and will never be supported.2) The older Arduino IDE's are not supported "out of the box".3) AVR eclipse is no longer part of the plugin so you you need this features you have to install avr eclipse next to the arduino eclipse plugin.4) Workspaces from version 1.X of the plugin are not compatible with this plugin.5) The possibilities to change the commands in the plugin have been removed. To change the build commands please modify the platform.txt file6) The reporting on the memory usage is less convenient.

Because of the incompatibility of the workspace I decided to release the plugin on a different update site. This allows you to switch to the new version when you are ready.

How to install the plugin?I strongly advice to make a completely separate eclipse installation to support the migration process. Workspaces are not compatible so do not try to open your current work spaces with this plugin without having taken the necessary measurements (such as backups).you need Eclipse Juno and Arduino IDE 1.5.2. Older versions of eclipse will not work (believe me I tested it) and older version of Arduino IDE will not work out of the box.To install the plugin goto the install new software in eclipse and set the following location:http://www.baeyens.it/eclipse/V2

Do not forget to configure (windows->preferences->arduino) or nothing will work. There is no error message in this case.

What do I mean with " older version of Arduino IDE will not work out of the box."?Arduino IDE 1.5.x tries to be tool independent. Therefore all "instructions" are described in a text format in platform.txt. The plugin uses the platform.txt to execute the commands. As older versions do not have a platform.txt file the plugin does not know which actions to take. So to run older versions you need to create/copy a platform.txt and place it next to the boards.txt.If you succeeded in doing so please share your success and findings.

eclipse pluginPosted by Jan Mon, March 04, 2013 18:26:48I released the alpha version of the of the arduino eclipse plugin 2.0.I tested on Linux and windows. Testers say it works fine on Mac.I'll give it some more time before I release a beta or final version.