Recent Changes - Search:

edit SideBar

ArduinoYun

How do I run standalone avrdude to program an Arduino Yun?"

We are glad you asked!

The problem we were having was that under Mac OS X, the Arduino program could successfully download software to the Arduino Yun.

However, when we ran avrdude by hand, we got butterfly_recv: programmer is not responding

The solution

  • We needed to push the reset button twice to really reset the board. The LED glows red - only during this time can the avrdude command be run.
  • Our workaround (many thanks to Mark!) is that we run the stty command, then sleep for one second, then run the avrdude command:
stty -f /dev/tty.usbmodem1421
sleep 1
# Then run the avrdude command
avrdude...

Getting started with the Mac

We are using the Arduino Yun

avrdude -c avr109 -p m32u4 -v -U lfuse:r:-:i -U hfuse:r:-:i -U efuse:r:-:i -P /dev/tty.usb_path_to_the_device_serial_port

So, the makefile gets:

PROGRAMMER = -c avr109
FUSES = -U lfuse:w:0x5e:m -U hfuse:w:0x99:m -U efuse:w:0xf3:m
  • Get the device, we looked at Arduino IDE TOols -> Port, which said: /dev/tty.usbmodem1421 or /dev/cu.usbmodem1421
    • Add -P /dev/tty.usbmodem1421 to the PROGRAMMER line in the Makefile
  • Run make flash
  • The Yun blinks, but we get "butterfly_recv: programmer is not responding"
  • Tip: from Gnichi: For the avrdude, Christopher, did you try to just flush the code to another arduino, i think the reason is maybe the bootloader on the arduino is broken. And make sure that the serial port of the arduino is not open for reading in another place. if it's an arduino uno simply :
/usr/bin/avr-objcopy -O ihex -R .eeprom main.elf main.hex
  • Update fuses to -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xfb:m, which is from the boards.txt from the Arduino program.

Using ino

Ino has been used to compile and upload to Arduino Yun.

Upload has the same issue.

Setup

March 6, 2014

Download http://arduino.cc/en/Main/Software#toc3. For the mac, I downloaded http://arduino.googlecode.com/files/arduino-1.0.5-macosx.zip

See http://arduino.cc/en/Guide/MacOSX for installation. Basically, unzip it in /Applications

Generating code to toggle an LED

What we want to is create models that use an Arduino-specific Display actor to toggle the LED. This is not that interesting, but gets us started.

  • How to generate code:
$PTII/bin/ptcg -generatorPackageList generic.program.procedural.c.arduino $PTII/ptolemy/cg/adapter/generic/program/procedural/c/arduino/adapters/ptolemy/actor/lib/gui/test/auto/Display.xml
  • The code we want to modify is at ptolemy/cg/adapter/generic/program/procedural/c/arduino/adapters/ptolemy/actor/lib/gui/Display.c
  • Things we need to do
    • We need modify the Display actor to generate a .c file is complete
      • proper includes
      • proper glue code
    • We need a makefile that will build the binary.
    • To upload to the Arduino Jun, we need to call stty 1200, sleep for a second and then call avr-dude.

Setting up on the Mac

Idea: use avr-gcc to compile the generated code. To do this, we need to set the path to include the avr tools:

export PATH=/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin:${PATH}

pbl.h: sys/dir.h not found

Solution:

#ifndef __CYGWIN__
#ifndef __AVR__
#include <sys/dir.h>
#endif
#endif

For us, the real fix was to edit ptolemy/cg/kernel/generic/program/procedural/c/structures/pbl.h

Problem with Infinity

Infinity was not defined, so we did:

#ifdef __AVR__
LED_SDF_Director->_stopTime = INFINITY;
#else
LED_SDF_Director->_stopTime = Infinity;
#endif

For us, the real fix was to edit ptolemy/cg/kernel/generic/program/procedural/c/SharedCode.c

#ifdef __AVR__
#define Infinity INFINITY
#else
#define Infinity HUGE_VAL
#endif

avr.h not found

Solution: Edit the makefile:

ARDUINOINCLUDES=-I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/
LED: LED_Main.c $(PTCG_CFILES)
avr-gcc -D__AVR__=1 $(ARDUINOINCLUDES) -D__int64="long long" $(WARNING_CC_FLAGS) $(CC_FLAGS) $(USER_CC_FLAGS) $(DEBUG) $(PTCGINCLUDES) $^ -o LED -lm $(PTCGLIBRARIES)

For us, the real fix was to do:

cp ./kernel/generic/program/procedural/c/makefile.in ./adapter/generic/program/procedural/c/arduino/

and then edit the new file.

io.h: device type not found

Message:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/avr/io.h:330:6: warning: #warning "device type not defined"

Solution: Look in io.h, find the appropriate device. For us on the Arduino Yun, it is __AVR_ATmega32U4__ so we add that to the makefile

Sample Blink Code

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

pbl.c has include problems.

Errors like:

commons/pbl.c:52:20: fatal error: memory.h: No such file or directory
#include <memory.h>
^

The fix is to edit the master pbl.c. First, find the pbl.c file:

bash-3.2$ find $PTII/ptolemy/cg -name pbl.c
/Users/cxh/ptII/ptolemy/cg/kernel/generic/program/procedural/c/structures/pbl.c
(:source:)

Then, edit file, change
(:source:)
#include <memory.h>

to

/* The Arduino does not have a memory.h file. */
#ifndef PT_DOES_NOT_HAVE_MEMORY_H
#include <memory.h>
#endif

Then, edit $PTII/ptolemy/cg/adapter/generic/program/procedural/c/arduino/makefile.in and add a define:

ARDUINO_DEFINES=-D__AVR__ -D__AVR_ATmega32U4__ -DPT_DOES_NOT_HAVE_MEMORY_H

The reason to use PT_DOES_NOT_HAVE_MEMORY_H instead of __AVR__ is so that if other platforms do not have a memory.h file, we can just define PT_DOES_NOT_HAVE_MEMORY_H in the makefile for that platform.

The makefile.in is a template makefile used when generating Arduino code. The makefile.in gets variable substitutions and $PTII/cg/LED.mk is created.

Next steps

Run

$PTII/bin/ptcg -generatorPackageList generic.program.procedural.c.arduino $PTII/ptolemy/cg/adapter/generic/program/procedural/c/arduino/adapters/ptolemy/actor/lib/gui/test/auto/Display.xml

Then edit the pbl .c and .h files in ptolemy/cg/kernel/generic/program/procedural/c/structures

Add defined to those files and to $PTII/ptolemy/cg/adapter/generic/program/procedural/c/arduino/makefile.in

May 8 Log

There were a series of issue:

  1. We did not have a loop() call in our generated code. Our hack was to add one that called the *_fire method of the embedded actor
  2. We had a .c file that defined main(), which prevented us from linking with the main() function in the library. In theory, we should be able to use our own main(), this would need further exploration.

Things we did to get Blink.xml working:

  • In foo.cpp, we added a loop() function in the last ifdef cplusplus -- Done--
  • rm *.hex *.elf core.a
  • Edit the makefile and comment out the line that includes the PTCG_CFILES because this line gets all the .c files
  • Remove Blink_Main.c Blink_Main.o

Things that would make this easier the next time:

  1. It took us a while to figure out that to update the chip, we needed to call stty, push the button twice and then run avr-dude.
  2. Use a simpler chip.
  3. Use a simulator

Things to do

  1. Blink.xml includes a loop() method that contains a hardwired call to the *_fire() method
  2. The Blink.xml.in is a bit of a mess
    1. We copy to foo.cpp
    2. The find . -type f -name "*.c" call is a hack and should be removed.
    3. We remove files that are generated
  3. It would be good to try some other models.

Future fixes

  • ptolemy/cg/adapter/generic/program/procedural/c/arduino/makefile.in
    • Set ARDUINOINCLUDES properly
    • PTCGCompiler?

Microsoft Remote Desktop on a Mac

Edit - History - Print - Recent Changes - Search
Page last modified on September 27, 2014, at 12:16 am