Koepel:
You better stop what you are doing. Tell us which Arduino board you use.
I hope you are not trying to blow the pins of the Raspberry Pi.
When you plug the Arduino board in the USB of the Raspberry Pi, then you have already a serial connection.
I am using an arduino Uno board, and a raspberry pi zero. The uno is connected through the USB cable to a desktop computer, and through the GPIO pins and a voltage level adapter circuit to the pi zero. That part is sound.
cattledog:
Please explain more about the data you are sending, the code which is receiving the data, what you are seeing and what you want to see.
The part of the code in charge of the communication is now through software serial, since I will need to use both anyway in the future and the USB connection is being used by the desktop to check the data sent is correct.
GasMeter sensor;
TinyGPS gps;
/* rx, tx */
SoftwareSerial soft_serial(2,3);
long latitude, longitude;
unsigned long age, resultado, date, time;
int session_id = 155;
void setup() {
sensor.initialize();
soft_serial.begin(9600);
}
void loop() {
while(Serial.available() !=0){
Serial.read();
}
if( sensor.get_reading(resultado)){
gps.get_position(latitude, longitude, age);
gps.get_datetime(date, time, age);
/*Testing output from the Arduino back to the computer to make sure it works*/
Serial.print("[R]");
Serial.println("Lectura del sensor");
Serial.println(resultado);
Serial.println("Latitud y longitud");
Serial.println(latitude);
Serial.println(longitude);
Serial.println("Fecha y hora");
Serial.println(date);
Serial.println(time);
soft_serial.print("[R]");
soft_serial.write((byte*) &session_id, sizeof(session_id));
soft_serial.write((byte*) &resultado, sizeof(resultado));
soft_serial.write((byte*) &latitude, sizeof(latitude));
soft_serial.write((byte*) &longitude, sizeof(longitude));
soft_serial.write((byte*) &date, sizeof(date));
soft_serial.write((byte*) &time, sizeof(time));
delay(500);
}
delay(1000-(millis()%1000));
}
And on the raspberry I'm running this script
#! /usr/bin/python3
import serial, sys
arguments = sys.argv
arguments.pop(0)
serialPort = arguments[0]
ser = serial.Serial()
ser.baudrate = 9600
ser.port = serialPort
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
try:
ser.open()
while True:
in_data = ser.read(3)
if (in_data==b'[R]'):
print(in_data.decode())
session_id = ser.read(2);
gas_received = ser.read(4);
latitude = ser.read(4);
longitude = ser.read(4);
date = ser.read(4);
time = ser.read(4);
print("session_id")
print(session_id.hex())
print("gas_received")
print(gas_received.hex())
print("latitude")
print(latitude.hex())
print("longitude")
print(longitude.hex())
print("date")
print(date.hex())
print("time")
print(time.hex())
except KeyboardInterrupt:
ser.close()
print("Closing")
pass
As it is right now, this is an output
[R]
session_id
9b00
gas_received
c8af0000
latitude
88130000
longitude
88130000
date
bcc50000
time
e826e500
If you see the received session_id, for example, its 9b00, where the hex value for 155 is 009b. So I would need to put the 0s before the data.