Wednesday, January 28, 2015

Connecting the ArbotixM with the Raspberry Pi, part 2

Pew, I thought for a moment that the patient had died. My troubles with writing the bootloader for the ArbotiX continued and some how and I always got a to low result on the Pololu USB AVR ISP programmer.   I resorted to resetting the firmware to the same as it already reported 1.0.7 vaguely remembering that I probably did this before as that version came after I acquired the device to begin with.  But what seem to do the trick in the end was reversing the programming cable and suddenly every thing went smoother than ever before, no complaints, just a satisfying 'Done burning bootloader' from the Arduino IDE.  Yay, now I can hurriedly rush towards the next wall to run face first into.

So lets get blinky installed on the arbotix from the Raspberry Pi.  To avoid repeating all the build parameter for the target board model and the serial interface we add a ino.ini file with the following configuration.

board-model = arbotix
serial-port = /dev/ttyUSB0

Use the dmesg command to figure out where your serial interface ends up. This is also safer as now we don't have to remember to add the flags which could have sad result if we accidentally build a Uno target and try to send that to the ArbotiX.  Next we clean the previous build stuff to be sure we have the right.  As the documentation for ino is a bit light outside the getting started I resorted to looking up the commands directory in the python code that was a bit more forth coming.  I could verify that there is indeed a clean command and that it basically just wipes the .build folder that can easily be overlooked as it is hidden by default due to the . in front of the name.  So lets execute:

$ ino clean

Build again, relying on the ino.ini to set the board model and serial port to use.

$ ino build

Then we upload to the device.

$ ino upload

That produces lots of rapid green light blinking and finally a happy 'avrdude done. Thank you.' message in console and a steady blinking light on the arbotix.  Seems like the mission is a success. We have a successful upload of firmware from a Raspberry Pi using the USB FTDI serial interface to the ArbotiX robot controller using command line.

Before I declare victory I try out the serial communications and create a new empty ino sketch.

$ mkdir serios
$ cd serios
$ ino init
$ nano src/sketch.ino

paste the serial code from the ino getting started replacing all the contents.

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    Serial.println(millis());
    delay(1000);
}

then I copy the ino.ini file from the blinky project over and build

$ cp ,,/blinky/ino.ini .
$ ino build
$ ino upload

Then I attempted to connect to the serial port using ino

$ ino serial

That failed as ino could not locate the picocom program it uses for the serial communications. Thankfully that was readily available via apt-get

$ sudo apt-get install picocom

After that things worked out better and I got a steady steam of millisecond readouts. Ctrl-A, Ctrl-X killed the session and normality was restored once more.

Next I will try to build the arbotix_ros firmware and see where that gets me. But that is a different story for later.

No comments: