I have just started working with the PI and would like to connect one of my Arduino projects to my PI for internet control.
I have connected the Arduino to the Raspberry Pi's GPIO with a CD4050 IC to bring the UART down to 3.3v.
I comment out this line in /etc/inittab
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
I am using SoftSerial on the arduino to passthrough.I removed this from /boot/cmdline.txt
console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
Code: Select all
/*
Connects Arduino to Raspberry Pi
Arduino: SoftSerial
Raspberry Pi: GPIO UART
This is just a simple passthrough, based on Arduino SoftSerial example
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
// Open serial communications to PC and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Connected to PC");
// set the data rate for the SoftwareSerial port to Raspberry Pi
mySerial.begin(9600);
}
void loop() // run over and over
{
// If data is available on Raspberry Pi, print it to PC
if (mySerial.available())
Serial.write(mySerial.read());
// If data is available on PC, print it to Raspberry Pi
if (Serial.available())
mySerial.write(Serial.read());
}I get M¹ÑɽµA%5jRj¤ü on the Arduino. But if I use.echo -e "Sent from PI \r\n" > /dev/ttyAMA0
I get ÿSent from PI (Not sure why I get ÿ at the start of each line??)sudo echo -e "Sent from PI \r\n" > /dev/ttyAMA0
I also did a test sending Serial from php and its the same, I get garbage on the arduino side.
My project is going to use php to send commands to the arduino.
If anyone could help me out that would be great.
Here is the php code.
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include "php_serial.class.php";
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyAMA0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->deviceOpen();
$serial->sendMessage("Hello from my PHP script.");
$serial->deviceClose();
echo "I've sended a message! \n\r";
?>