Main Menu

FTDI

Started by |MeRoBo|, October 24, 2013, 07:47:42 PM

|MeRoBo|

Hi, Is it possible to upload sketches to the moteino via the Raspberry Pi's GPIO pins without a FTDI adapter?

Felix

I haven't done it but I'm sure it's possible.
Searching google for "raspberry pi arduino IDE" reveals tons of links: https://www.google.com/search?q=raspberrypi+arduino&oq=raspberrypi+arduino

You need to free the hardware serial port, and connect a GPIO to the RTS/DTR of the Moteino/FTDI in. So you need to reset the board to make it go in the bootloader.
I'm not sure how this can be achieved directly from the Arduino IDE running on the Pi. Perhaps setting up some script that pulls the RTS down then quickly run avrdude with the right arguments.

jbeale

#2
If you don't need automated, unattended programming, you can simply momentarily short the AT328p RESET pin to GND with a wire, tweezers etc. at the right time (as soon as the IDE says its uploading). I've done this plenty of times with various arduino-equivalents and it works.
On the Moteino, RESET is at the lower-right corner in the image below, right next to the FTDI GND pin, so shorting them is quite easy.
http://lowpowerlab.com/wp-content/uploads/2013/03/Moteino_PINOUT_final2.png

NOTE: I have not actually tried this manual reset upload on the Moteino, which uses a different bootloader than the earlier "Duemilanove" units I used.

Felix

jbeale is right, I have done it manually on the Moteino many times. If you just want to upload sporadically, short the RST to GND and then quickly click Upload or run avrdude. Once reset the board will stay in the bootloader for about 1-2 seconds waiting for an upload.

|MeRoBo|

Ok from the looks of it, it will be more of a headache.

Could I use the Moteino-usb as a ftdi for the other moteino's?

I want to have a gateway but still need to program the other nodes, so instead of buying a ftdi + Motieno as a gateway + 2 nodes, buy a moteino-usb to be the gateway/ftdi adapter for the 2 extra nodes. 

|MeRoBo|


Felix

Sure could, but then you gotta load jeelib on all the nodes, I don't support that library.
The little RFM12B board is just a breakout, has no MCU, so you have to run a separate program on your pi/beaglebone to do what a Moteino would normally do. But it's up to you...

halibatsuiba

Howdy y'all.

Yes, it is possible to upload hexfiles from Raspberry Pi to Moteino with just three wires.

I am building a home automation system and currently I am in a process of getting gateway up and running.
As a gateway I am using Raspberry with Moebius  ( http://moebiuslinux.sourceforge.net/).
For programming the Moteino I am using avrdude-rpi (https://github.com/deanmao/avrdude-rpi)

And here is how to get it working (I may have forgotten something but that's what age does):

1. Install and configure Raspberry with Moebius (or some other distro, does not matter)
2. Install Python and RPi.GPIO
3. Install avrdude
4. Download avrdude-rpi, install it as per instructions
5. Fix the autoreset in /usr/bin

The "autoreset"-script that comes with avrdude-rpi has an error in it. Lines 14-19 say:

def reset():
  pin = 11
  GPIO.setup(pin, GPIO.OUT)
  GPIO.output(pin, GPIO.HIGH)
  time.sleep(0.12)
  GPIO.output(pin, GPIO.LOW)

This is incorrect, should be:

def reset():
  pin = 11
  GPIO.setup(pin, GPIO.OUT)
  GPIO.output(pin, GPIO.LOW)
  time.sleep(0.12)
  GPIO.output(pin, GPIO.HIGH)

6. Install Minicom (so you can test the connection. This is important)
7. Make sure you have one Moteino with working sketch uploaded (something that prints out and reads through serial port, the default receiver or sender is a good choice here)

Connect raspberry and Moteino (NOTE! You may damage either/both boards if you connect them while they
are powered on. You may even damage them if you connect them this way because there is no any kind of protection circuitry in use. Consider yourself warned and do this at your own risk.):

Rasp (pin#)        Moteino
UART Tx (8 ) --- FTDI Rx
UART Rx (10) --- FTDI Tx
GPIO 17 (11) --- Reset (RST)
GND (6) --- GND
5V (4) --- Vin

Yes, I said "three wires". I just happen to power Moteino from Raspberry...

Everything did not go as in movies though.
I could not get connection working, took several hours to figure out it was a faulty wire!
Replaced wire and after that Moteino printed nice debugging info to Minicom and even obeyed commands
like "d" or "i" (with receiver sketch).
After that it took another several hours to figure out the autoreset bug.

So now when you have everything up and running, use minicom (or some other serial terminal sw) to verify
you have connected everything ok. (send "i" to Moteino and if there is no "DeviceID..." on screen, check wiring).

If life is good and everything works so far, you are ready to try avrdude. But first you need a hex-file.

One way to get one for testing is as follows:
-Start Arduino IDE (in Raspberry or in some other computer, does not really matter here).
-Go to File/Preferences
-Put checkmark to "Show verbose output during: compilation [ ]"
-Click OK
-Open one of the example sketches, Blink is a good choice here.
-Change "int led = 13;" to "int led = 9;"
-Click "Verify"
Now on console output there is a line telling where the hexfile is located. Copy that file to Raspberry if you did not compile it there already.

And now the moment of truth, test if avrdude works.
Type in command "avrdude -b 115200 -p m328p -c arduino -P /dev/ttyAMA0 -U flash:w:Receiver.cpp.hex"
(Receiver.cpp.hex is the hexfile I was using).
Cross your fingers, take a deep breath and press enter.

Don't worry if it does not work right away. Took me a whole day to get this working.

But if, for some reason, the led in Moteino blinks steadily on-off-on-... you have succeeded and you should reward yourself with your favourite beverage.  8)

(If avrdude spits out something like "programmer not responding" or some hex error messages, double-recheck the wires.)

Good luck.

Felix

Cool, this should help folks that are trying to interact with Moteinos directly from the RaspberryPi, thanks for sharing your experience!

nicocarv

Guys, I have been trying this and when compiling for the Moteino Mega I got the following error.

I have added the MEGA folder to the hardware folder of arduino.

Any idea?

Tnx!
Nico

Felix

Please load Arduino 1.0.6 and load the new core from here: https://github.com/LowPowerLab/Moteino/tree/master/MEGA/Core

Charly86

Like halibatsuiba said (same method), you will find an article there http://hallard.me/arduipi-getting-started/ describing how to program Arduino (Moteino) from PI directly using a GPIO as reset Pin (GPIO18 in the example).

The example apply for an ArduiPi board, but it's the same way, 3 wires, RX, TX and DTR (here GPIO18). Use direct connexions from Pi to Arduino only if Arduino is running 3.3V, but it's fine, it's the case with moteino.

See section :
Uploading Sketches to Arduino
then  Directly from Raspberry using Raspberry PI integrated UART

Installation is straight forward, just follow the command and you're done

sudo apt-get update
sudo apt-get install python-setuptools
sudo easy_install rpi.gpio
wget https://github.com/hallard/arduipi/raw/master/raspberry/autoreset
wget https://github.com/hallard/arduipi/raw/master/raspberry/avrdude-autoreset
wget https://github.com/hallard/arduipi/raw/master/raspberry/reset-arduino
sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
sudo cp autoreset /usr/bin
sudo cp avrdude-autoreset /usr/bin
sudo cp reset-arduino /usr/bin
sudo chmod ug+x /usr/bin/avrdude-autoreset
sudo chmod ug+x /usr/bin/autoreset
sudo chmod ug+x /usr/bin/reset-arduino
sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude


nicocarv


nicocarv

Hey Felix,

I couldn't find the arduino IDE 1.0.6 for raspberry. The newest is 1.0.5. (I uploaded the last version of the arduino core for the MEGA)
I tried to search for the error when compilling, but did not know what to do. I'm attaching a photo in case you can give me a hand.

Thanks a lot!
Nico

Felix

Sorry i dont know what to suggest, at least verify the core is installed properly in the right location.
I havent used the IDE for Pi.