Yun, johnny-five and firmata question

Hi Guys,

I wanted to run johnny-five.js on the arduino-yun’s Linux/Linino (Atheros AR933) and talk to the Arduino (MCU;32U4) on the other side.

It took me like two nights to figure it out properly, but it works until the reboot. The hints are on many sites - so I thought i’d consolidate it.

Prepare the Yun’s Arduino

You need more space, buy a 8GB micro-sd card and format it with the YunDiskSpaceExpander sketch. Add like 1000mb for sda1.

Open the sketch Firmata / StandardFirmata and comment the following line

  // Firmata.begin(57600);

and replace it with

  Serial1.begin(57600);
  Firmata.begin(Serial1);

Upload the new sketch (It will ask you for a new file name).

Prepare the Yun’s Linux

(Make sure your Disks is expanded by running above’s YunDiskSpaceExpander sketch).

Use /dev/sda1 as swap

  umount /mnt/sda1
  mkswap -f /dev/sda1
  swapon /dev/sda1

Install the packages

  cd /opt
  opkg update
  # vi sometimes generates xterm errors
  opkg install vim
  opkg install node
  opkg install node-serialport
  npm install johnny-five

Modify /etc/inittab

  sed -i -e 's/ttyATH0/# ttyATH0/g' /etc/inittab

Modify the board setup e.g. in led-strobe.js

  var five = require("johnny-five");
  var serialport = require("serialport");
  var led;
   
  var serialPort = new serialport.SerialPort("/dev/ttyATH0", {
           baudrate: 57600
   });
  var board = new five.Board({
              port: serialPort,
              debug: true
    });
  board.on("ready", function() {

    // Create a standard `led` hardware instance
    led = new five.Led(13);

    // "strobe" the led in 100ms on-off phases
    led.strobe(100);
  })

And it blinks nicely

  root@yun12:/opt# node led-strobe.js
  1418849951091 SerialPort /dev/ttyATH0
  1418849956331 Connected /dev/ttyATH0
  1418849956338 Repl Initialized

But when I reboot the YUN, it won't start up, no white usb light nada. Then I basically have to overwrite the sketch to make the yun accessible again. Its probably something with the firmata modification to Serial1. How can I make that poperly?

Ha! found a hack around: sleep for like a minute before running the sketch. Pretty? Hell no, but it works :-)

void setup()
{
  delay(60000);

  Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

  Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
  Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
  Firmata.attach(REPORT_ANALOG, reportAnalogCallback);
  Firmata.attach(REPORT_DIGITAL, reportDigitalCallback);
  Firmata.attach(SET_PIN_MODE, setPinModeCallback);
  Firmata.attach(START_SYSEX, sysexCallback);
  Firmata.attach(SYSTEM_RESET, systemResetCallback);

  Serial1.begin(57600); // Set the baud.

  Firmata.begin(Serial1);
  systemResetCallback();  // reset to default config
}

i need help!! please! once i Use /dev/sda1 as swap , the system cant detect the sd card once it is connected to my comp-to upload the nodejs file

2)and for windows,how do i Modify /etc/inittab ?

i hope i can get a reply soon Thank you!