Baris Sanli's Raspberry Pi and Gertboard Resources

Arduino ile Webserver-ESP8266
Spark Core Energy Monitor
Connecting Raspberry
Error Message
Serial Communication
Interfacing LCD

A Serial Communication between ATMEGA328p (Gertboard) and Raspberry Pi

Setup: Raspberry Pi, Gertboard, 2 jumpers

Warning : If you are not using Gertboard, do not power up ATMEGA328p with 5 V, this will damage Raspberry Pi!

First of all, let's make sure that all the jumpers are in place, including the standart 3V3 jumper...

  • The jumpers on the left (J6) are
    Jumper - between MCTX-GP15
    Jumper - between MCRX-GP14

After getting the jumpers ready, from Raspberry Pi compile and "upload using programmer", the following code

-----------------------This is the code for Arduino-----------------------------------------

char incomingByte=0;
char inData[20];
int x=0;

void setup() {
// initialize serial:
  Serial.begin(9600);
}

void loop() {
  Serial.print("hello print");
  x=0;
 while (Serial.available()>0){
   incomingByte=Serial.read();
   inData[x]=incomingByte;
   inData[x+1]='\0'; x++;
   }
  Serial.println(inData);
  delay(1000);
}
-----------------------------------------------------------------------------------------------------

On the Raspberry Pi, run the following python code :
-----------------------This is the code for Raspberry Pi-----------------------------------------
from time import gmtime, strftime
import time
import serial
import struct

ser = serial.Serial("/dev/ttyAMA0", 9600)
while 1:
  ser.write("testing")
  temp=strftime("%Y-%m-%d %H:%M:%S", gmtime())+'\t'+ser.readline()
  print(temp)
  time.sleep(1)
-----------------------------------------------------------------------------------------------------

 


emailto : barissanli2@gmail.com