Lakster37
Posts: 2
Joined: Fri Jan 24, 2014 5:30 am

Connecting to Gertduino via serial

Fri Jan 24, 2014 6:01 am

First, I'd like to say that I'm quite new to both Raspberry Pi and Arduino, but thought it'd be good to learn them both together. ;) I'm using the Arduino IDE to program the 328 and have already successfully uploaded several sketches via GPIO. However, I want to be able to use the Serial Monitor of Arduino IDE to be able to read data that has been input to the arduino and so I need to set-up a serial connection. I've cross-linked the TX/RX lines as shown in the manual, but the serial line doesn't seem to be recognized because I just get the error
Serial port 'COM1' not found. Did you select the right one from the Tools > Serial Port menu?
(Incidentally, the Serial Port menu is greyed out). All of the issues I've seen posted on these forums regarding serial communication seem to have already gotten past this step (they've been able to actually get some kind of communication between the Pi and Gertduino) so I couldn't find much to help me troubleshoot. I have edited the two files (cmdline.txt and innitlab) as described here. However, I'm not familiar with Python so I'd prefer to use the Arduino IDE to communicate over serial rather than a Python script, at least for now.

Do I need some sort of additional driver to be able to connect via RS232? I did see that normally with an Arduino connected via USB you have to install certain drivers, but since the Gertduino doesn't use the same FTDI chip (and it uses RS232 rather than USB) I couldn't find any suitable drivers from some quick searches.

Also, once the 328 is programmed, do I still need the jumpers in place as described in the Manual on page 6 for GPIO programming if all I'm doing is reading and sending data over RS232? I'm currently using the provided jumpers (along with two male-male jumper wires) to cross-over the RX-TX pins.

Finally, is there any easier/"better" way to receive/send packets of data from the Arduino, whether it be with the Arduino IDE or avrdude or whatever else? Thanks!

User avatar
AndyD
Posts: 2326
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Connecting to Gertduino via serial

Fri Jan 24, 2014 9:25 am

Lakster37 wrote:I want to be able to use the Serial Monitor of Arduino IDE to be able to read data that has been input to the arduino...
Hi, I have not been able to get the Serial Monitor of the Arduino IDE working with the Gertduino. I have used the program minicom instead an this works nicely. You will need to install it first.

Code: Select all

sudo apt-get install minicom
Lakster37 wrote:Do I need some sort of additional driver to be able to connect via RS232? ...
No, I don't believe so. Just use minicom it will be easier.
Lakster37 wrote:...once the 328 is programmed, do I still need the jumpers in place as described in the Manual on page 6 for GPIO programming if all I'm doing is reading and sending data over RS232? I'm currently using the provided jumpers (along with two male-male jumper wires) to cross-over the RX-TX pins.
Once you have a program running on the 328 you don't need to have the jumper in place. Just the cross over wires for the serial link.
Lakster37 wrote:Finally, is there any easier/"better" way to receive/send packets of data from the Arduino...
No, I think serial is the way to go.

achrn
Posts: 311
Joined: Wed Feb 13, 2013 1:22 pm

Re: Connecting to Gertduino via serial

Fri Jan 24, 2014 9:37 am

Lakster37 wrote: Finally, is there any easier/"better" way to receive/send packets of data from the Arduino, whether it be with the Arduino IDE or avrdude or whatever else? Thanks!
If it's a discrete actual arduino (rather than gertduino or something intended to interface direct to Pi) then it's possible that feeding it via USB is easier. It's still serial as far as your coding sees it, but if you're using an arduino with built-in USB then hooking up the wires is slightly easier and you don't need to worry about level shifters.

I like the arduino nano for this purpose - small, built-in usb, no silly pin spacing. I've had no problem with the Arduino IDE serial monitor on Pi talking to a nano over usb.

Beware the nano hardware bug though if you buy a cheap clone - see http://www.astounding.org.uk/ian/raspi- ... nofix.html

User avatar
AndyD
Posts: 2326
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Connecting to Gertduino via serial

Fri Jan 24, 2014 9:45 am

achrn wrote:I like the arduino nano for this purpose - small, built-in usb, no silly pin spacing. I've had no problem with the Arduino IDE serial monitor on Pi talking to a nano over usb.

Beware the nano hardware bug though if you buy a cheap clone - see http://www.astounding.org.uk/ian/raspi- ... nofix.html
Yes, me too!

Lakster37
Posts: 2
Joined: Fri Jan 24, 2014 5:30 am

Re: Connecting to Gertduino via serial

Sun Jan 26, 2014 4:43 am

Thanks for the help, guys. I got minicom to work.

tfpratt
Posts: 7
Joined: Tue Apr 08, 2014 1:34 am

Re: Connecting to Gertduino via serial

Thu Apr 10, 2014 1:38 am

Hi folks, complete n00b here. I am having a similar problem seeing the serial communications from the gertduino. Like the OP, I have edited the 2 text files in question, I have the gertduino jumpers in place (also the programming jumpers), I've installed minicom.

On the Arduino IDE, I've triple checked that my settings are:
Board = Gertduino with ATMega328 (GPIO)
Programmer = Raspberry Pi (GPIO)

I'm running a simple sketch:

Code: Select all

void setup(){
  Serial.begin(9600);
  Serial.println("Is there anybody out there?");
}
void loop() {}
I'm opening minicom using:
minicom -b 9600 -D /dev/ttyAMA0[/code]
The screen shows:
Welcome to minicom 2.6.1

OPTIONS: Il8n
Compiled on Apr 28 2012, 19:24:31.
Port /dev/ttyAMA0

Press CTRL-A Z for help on special keys
What else should I be doing to see the output? In the minicom window it says 'offline', but I'm not sure how to make it 'online'. I've ran through all the settings and tried to google to ensure I'm using the correct device.

Pre-thanks for any help!

-Todd

racpi
Posts: 33
Joined: Mon Dec 30, 2013 11:54 am
Location: australia

Re: Connecting to Gertduino via serial

Thu Apr 10, 2014 10:58 pm

don't forget the pi holds the gertduino reset low until you run gerts reset_off script or remove the reset jumper.

tfpratt
Posts: 7
Joined: Tue Apr 08, 2014 1:34 am

Re: Connecting to Gertduino via serial

Sat Apr 12, 2014 12:29 pm

don't forget the pi holds the gertduino reset low until you run gerts reset_off script or remove the reset jumper.
I googled the reset_off script without avail. I tried removing the programming jumpers, but got an error in the sketch above, which was fixed when I put them back on. Can you point me to a source regarding the reset jumper or script and what it does in relation to seeing output in minicom?

Thanks for the reply!

Todd

User avatar
Gert van Loo
Posts: 2474
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Connecting to Gertduino via serial

Sat Apr 12, 2014 7:47 pm

Have you connected up the serial ports between the Pi and the 328 chip?
See the Gertduino manual section which is available here:
http://www.element14.com/community/comm ... /gertduino

Page five top right picture: Pi to Atmega-328

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Connecting to Gertduino via serial

Sun Apr 13, 2014 12:55 pm

You're only sending your text once. You might want to move the Serial.println into the loop.
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

tfpratt
Posts: 7
Joined: Tue Apr 08, 2014 1:34 am

Re: Connecting to Gertduino via serial

Thu Apr 17, 2014 10:25 pm

Gert van Loo wrote:Have you connected up the serial ports between the Pi and the 328 chip?
See the Gertduino manual section which is available here:
http://www.element14.com/community/comm ... /gertduino

Page five top right picture: Pi to Atmega-328

Hi Gert,

Sorry for the slow reply, was on vacation. I have the jumpers set and included a picture in case I've done it incorrectly.

-Todd
Attachments
serial_jumpers.jpg
Serial Jumpers
serial_jumpers.jpg (38.61 KiB) Viewed 11965 times

tfpratt
Posts: 7
Joined: Tue Apr 08, 2014 1:34 am

Re: Connecting to Gertduino via serial

Thu Apr 17, 2014 10:32 pm

Jednorozec wrote:You're only sending your text once. You might want to move the Serial.println into the loop.
Thanks for the help. I've updated the sketch to read:

Code: Select all

void setup(){
  Serial.begin(9600);
}
void loop() {
  Serial.println("Is there anybody out there?");
}
Unfortunately I still do not see a result in the minicom screen.

User avatar
Gert van Loo
Posts: 2474
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Connecting to Gertduino via serial

Fri Apr 18, 2014 10:57 am

Ahh!
You re trying to talk to the 48 !!
Beware that it runs of a different frequency (Either 8 or 1 MHz, not 16MHz)
so you have to adjust the baud rate for that.

tfpratt
Posts: 7
Joined: Tue Apr 08, 2014 1:34 am

Re: Connecting to Gertduino via serial

Tue Apr 22, 2014 12:43 am

Aha! That was it! I'm ashamed to say that I wasn't actually trying to talk to the 48, but had put the jumpers in the wrong positions for the 328. I corrected the jumpers and can see the serial output now. Thanks again Gert. Now to try and hook up an input device!

-Todd

billvance
Posts: 12
Joined: Mon Jan 20, 2014 5:05 pm

Re: Connecting to Gertduino via serial

Wed Sep 10, 2014 12:53 pm

I don't have a gertduino yet, but I've been
reading up on it and the alamode boards. One
of the things mentioned for both, is the less then
fully featured serial intefaces, i.e., no CTS/RTS
signals. Most people set these up as 8N1, or
8 bits, no parity bits, and one stop bit. Available
are two parity bits, and two stop bits, (one being
used). Of the 3 unused bits, couldn't two of
them be programmed as a sort of software
version of CTS/RTS?

Bill

RobinGreig
Posts: 13
Joined: Sat Oct 27, 2012 2:40 am
Location: Calgary, Alberta, Canada

Re: Connecting to Gertduino via serial

Sun Jan 04, 2015 4:20 pm

Hello all and Happy New Year!

Thanks to all included on this post as well as Gordon Henderson for his fine work.
Because of this post, I've been able to successfully communicate with my 328 via raspi.
And upload sketches via the arduino IDE on the raspi

However, I've got an ongoing issue where I've uploaded the sample arduino sketch - AnalogueReadSerial
which simply reads an analogue signal from a pottentiometer and outputs that value to the serial port.

Using minicom on the raspi, I can see that the value varies between 0 & 1024 depending upon the position of the pott.

Code: Select all

minicom -b 9600 -D /dev/ttyAMAp
So far, so good....

However, when I run this python program on my raspi,

Code: Select all

#!/usr/bin/env python

import serial
import time

count = 0
while (1):
  ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=5)
  time.sleep(1) # wait for arduino
  print "Count = ", (count)
  print ser.readline()
#  ser.close()
  time.sleep(1)
  count = count + 1
The resultant count doesn't change, as you can see below.
I am varying the Pott from full Min to full Max, and the serial output is not changing from 549.
[email protected] ~/python $ ./battery_voltage.py
Count = 0
549

Count = 1
549

Count = 2
549

Count = 3
549
I hit Ctrl-Z to exit the program, and go back and restart minicom and the value tracks with my Pott. setting.
So I know that the arduino is outputting the correct value, and the raspi is seeing it (according to minicom).

I'm just not sure why my little python program is not showing the changing value as I vary the Pott.

I've been googling various sites for the last several hours and everything I read tells me that this should work?

Any thought on what I am missing?

Thanks,
Robin
www.robingreig.ca
Arduino + Raspi + Amateur Radio enthusiast since 2012
VE6RBN Canadian Amateur Radio Callsign

danjperron
Posts: 3031
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Connecting to Gertduino via serial

Sun Jan 04, 2015 4:51 pm

Is the arduino code 'AnalogInOutSerial'?

If it is, the problem could be explain by this.

the serial output send info every n ms when n= convertion Times * 2 + 2 ms + time to send data.

Your python code wait 1 second and read the line. Obviously you will fill the Rapsberry Pi serial input buffer and eventually you will loose data. The behavior will be like you explain since you will display in 100 second what append in 1 sec.

You have to choose which device control the output. The arduino send info every ~100th of second but your python code only display the data every second. Data start to pile up. you feed ~100 data per second but you pull only 1 per second.

Remove the sleep in your python code and change the arduino code to send info every second.

It is possible to change the Python code only by flushing the input buffer first and read the line twice and only keep the last line read. The first line could be cut because of the flushing .

Daniel

RobinGreig
Posts: 13
Joined: Sat Oct 27, 2012 2:40 am
Location: Calgary, Alberta, Canada

Re: Connecting to Gertduino via serial

Sun Jan 04, 2015 8:08 pm

danjperron wrote:If it is, the problem could be explain by this.

the serial output send info every n ms when n= convertion Times * 2 + 2 ms + time to send data.

Your python code wait 1 second and read the line. Obviously you will fill the Rapsberry Pi serial input buffer and eventually you will loose data. The behavior will be like you explain since you will display in 100 second what append in 1 sec.

It is possible to change the Python code only by flushing the input buffer first and read the line twice and only keep the last line read. The first line could be cut because of the flushing .
Daniel
Thanks Daniel for the great explanation;
That makes a lot of sense to me.
I would like to be able to try as you suggest, to flush the input buffer first and then send a command to the arduino to send the the line twice.
I'll discard the first and read the second.
How could I go about doing that?
I'm not sure what python command would flush the raspi input buffer
Robin
www.robingreig.ca
Arduino + Raspi + Amateur Radio enthusiast since 2012
VE6RBN Canadian Amateur Radio Callsign

danjperron
Posts: 3031
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Connecting to Gertduino via serial

Sun Jan 04, 2015 9:44 pm

something like,

Code: Select all

#!/usr/bin/env python

import serial
import time

count = 0

ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=5)

while True:
  ser.flushInput()
  for i in range(2):
    line = ser.readline()
  print "Count= {0}  A/D= {1}".format(count,line),
  count = count +1
  time.sleep(1)
B.T.W. I found AnalogueReadSerial example and it is just one way. it send data every 1ms+conversion time+ transmission time. There is no handshake between the Raspberry PI and the Gerduino unless you modify the code to wait for a special character or string before transmitting again.

danjperron
Posts: 3031
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Connecting to Gertduino via serial

Sun Jan 04, 2015 11:31 pm

The best approach will be to have the Gertuino waiting for a command.

This is the code I wrote, as an example, using an arduino micro. The arduino will respond when it receives an ascii character from '0' to '5' and will output the A/D value of the pin A0 to A5. This method is a standard master slave mode. The arduino wait and respond from the Rpi command.


This is the Arduino code

Code: Select all

const int analogInTable[6]= {A0,A1,A2,A3,A4,A5};

char inChar;

void sendAnalogValue(byte Channel)
{
  
  int valueAD;
  valueAD = analogRead(analogInTable[Channel]);
  Serial.print("A");
  Serial.print(Channel);
  Serial.print("=");
  Serial.println(valueAD); 
}



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

void loop() {
  
  if(Serial.available() > 0)
    {
      
      inChar = Serial.read(); // read character
      
      if((inChar>='0') && (inChar <='5'))
         sendAnalogValue(inChar - '0');
    }
  delay(1);      
}
And this is the Python code

Code: Select all

#!/usr/bin/env python

import serial
import time

count = 0

ser = serial.Serial('/dev/ttyACM0', 9600, timeout=5)

while True:
  ser.flushInput()

  print "Count= {0}".format(count)
  #ok read all Analog
  for i in range(6):
    ser.write(chr(48+i))
    line = ser.readline()
    print "\t{0}".format(line),
  count = count +1
  time.sleep(1)
and the display output

Code: Select all

[email protected] ~ $ python ad.py
Count= 0
	A0=341
	A1=319
	A2=309
	A3=306
	A4=308
	A5=315
Count= 1
	A0=332
	A1=313
	A2=304
	A3=299
	A4=301
	A5=306

Now you could add your code to read or write digital output.

P.S. The arduino micro has a USB adapter and the Raspberry PI will see it as /dev/ttyACM0. Don't forget to change it to ttyAMA0

Daniel

RobinGreig
Posts: 13
Joined: Sat Oct 27, 2012 2:40 am
Location: Calgary, Alberta, Canada

Re: Connecting to Gertduino via serial

Mon Jan 05, 2015 12:12 am

Daniel;

Thanks again for the help, this has cleared up the issue and actually answered a couple of other challenges that I was struggling with.

I am designing a UPS for my Raspberry Pi and the arduino is going to be the battery watchdog.
I'm designing it for remote applications.

My primary battery will be a 12VDC Gel Cell recharged by a solar panel, feeding a voltage regulator to the raspi.
However, if there is little sun, and the battery voltage drops to a preset level, the arduino will activate a 110VAC battery charger to top up the battery.

If the power is not restored, for example, if there is a power outage, and the battery voltage drops even further then the arduino will send a signal to the raspi to poweroff and then will open a relay to the raspi power circuit.

Then once the battery voltage starts to return, the arduino will start and confirm battery voltage has stabilized, and then will power up the raspi.

I'm trying to blog about some of the process here, www.robingreig.ca

Thanks again, this has really helped me out,
Robin
www.robingreig.ca
Arduino + Raspi + Amateur Radio enthusiast since 2012
VE6RBN Canadian Amateur Radio Callsign

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 4 guests