Google Analytics

Tuesday, March 20, 2012

Using Arduino to read embedded AVR

If you are needing to communicate with an embedded project, then this may be the solution you need!

Building a stand-alone device such as a Multi-channel Thermocouple Reader with Datalogger is an ambitious project for a hobbyest.  Since it is my own design, it means, on my first cut, there isn't a PCB - everything is hand soldered - thus multiple opportunities for problems.

Being a stand-alone, embedded application (not built around Aruduino board, but instead built using the ATMEGA328P chip that is used on an Arduino) means Arduino's useful USB connection isn't there.

Program updates are pushed onto the ATMEGA chip via a ISP header I placed onto the board, using a programmer (in this case, I'm using the USBtinyISP programmer from Adafruit).   The ISP interface, which makes use of the MISO/MOSI interface, does not provide a way to communicate directly with the Arduino IDE Serial Monitor directly, so there's no easy way for me to observe data from the embedded ATMEGA, like there is on the Arduino (via Serial.print() statements).

I programmed some 'blink()' status LEDs, and that worked, but it is slow.  At some point during the build, I had enough working that I could output data directly to the SD Card, but to read that data entailed shutting down the power, pulling the card, inserting it into the PC, opening the file and reading it.  Reverse to put the card back into my project - slow....

I began to wonder if there wasn't some way I could use a separate Arduino UNO to serve as a communication hub between my embedded project and the PC running the Serial Monitor.

Looking around, I spotted this, which is using an Arduino to push a program onto an embedded chip.

There are two key things to take away from the schematic for the UNO:

  • The USB on the Arduino has an additional ATMEGA chip that enables communications, and sits between the USB and the ATMEGA328P that we program our projects onto.  
  • The TX and RX connections are used between these two chips for communications.
So, since these two chips are communicating, which is what I was wanting to do, I thought I should be able to emulate this connection.  I was getting all complicated with this before I spotted the statement: "To do, you remove the microcontroller from the Arduino board ", which meant I could pull out the Arduino's ATMEGA328P chip, then connect to my project, using the Arduino's RX and TX header (D0 & D1 on my Arduino).

I had been careful to keep the RX & TX pins unused on my project board, so it was a simple matter of soldering in two wires that I could then plug into the Arduino's RX & TX header.

Then I added some Serial.print() statements into my embedded project, and cranked it up and .... nothing appeared on my IDE's Serial Monitor.

So I reversed the wires, because this is a common issue with RX & TX - RX on one board has to connect to TX on the other board, and vice-verse, and you never know how it's been defined between the two boards, so always try swapping if it doesn't work.  

BANJO!  

It worked!  I was seeing my Serial.print() statements streaming by from my embedded project, using the Arduino as the communications hub!

1 comment: