Indice degli argomenti
Follow instrucctions from: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c , wich is mearly a thing about putting:
Test I2C:
i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
In order to have RPi serial -> FTDI USB we need TX/Rx and ground. Always check FTDI V setting: RPI is not 5v tolerant.
RPi default is to bring up serial to the serial console.
In order to use the UART for something different than console login these have to be commented and removed, then reboot (or manage inetd).
In order to test that the line is available launch a serial connection between two hosts:
conny: screen /dev/ttyUSB0 115200
rpi: screen /dev/ttyAMA0 115200
We are going to have first a terminal connection on RPi:
screen /dev/ttyAMA0 9600
Then a sketch running on Arduino (Uno in this case):
byte number = 0;
void setup() {
byte number = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
number = Serial.read();
Serial.print("character recieved: ");
Serial.println(number, DEC);
Serial.flush();
}
}
Wiring should be like: http://blog.oscarliang.net/ctt/uploads/2013/05/wiring.png with a Logic level converter. Consider that:
Whatever, now let’s make a script on RPI to check the serial connection, first install python serial `` apt-get install python3-serial``
#! /usr/bin/python3
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
ser.isOpen()
sample = "hello"
ser.write(bytes(sample.encode('ascii')))
try:
while 1:
response = ser.readline()
print(response)
except KeyboardInterrupt:
ser.close()