Array between 2 arduinos - I2C

@Power_Broker

Okay, I have installed the library via python3. It works! I was being stubborn to keep using py 2.7.

I had a look online and apparently python will stop supporting python 2.7 in january 2020, then no point to continue on 2.7.

Thank you

Cheers

Power_Broker:
I guess I can make it backwards compatible, but you need to realize that Python 2 is unsupported and you really should update your code to Python 3 or greater

Hello @Power_Boker,

I have used your following Python code slightly modified for sending a list of interger independent of the list of received data, see below.

My needs:
-Send a list of initial “output” integer from Raspberry to Arduino,
-process this list in Arduino,
-then send a different list of “input” integer from Arduino to Raspberry.
-Then receive this list in Raspberry,

  • process it,
    -and send back a updated list of “output” integer from Raspberry to Arduino
    -and so on need

I have use first this python code with your “Arduino Send Back data”, see below, it works fine. However, in the current “Arduino Send Back data” code we cannot interact with data received or sent.

I would like to use the data sent to Arduino into Arduino code and send another list of data (integer) from Arduino to raspberry which this example code does not allow.

I have then combined 2 examples of Arduino code Receiving Data “uart-rx-data” and Sending Data “uart-tx-data”. But it does not work as I expected, I receive into the Raspberry pi some random integer in a list. It would be very helpfull if you can help me to make it work.

Code Python:
import time
from pySerialTransfer import pySerialTransfer as txfer

if name == main:
try:
link = txfer.SerialTransfer(’/dev/ttyACM0’)
link.open()
time.sleep(2) # allow some time for the Arduino to completely reset
while True:
##################### Send Data to Arduino “”#####################
Value1=1024
Value2=1010
send_size = 0
###################################################################

  • Send a list*

  • ###################################################################*
    list_Send = [Value1, Value2]
    list_size_Send = link.tx_obj(list_Send)
    send_size += list_size_Send
    ###################################################################
  • Transmit all the data to send in a single packet*

  • ###################################################################*
    link.send(send_size)
    ###################################################################
  • Wait for a response and report any errors while receiving packets*

  • ###################################################################*
    print(‘SENT: {}’.format(list_Send[0]))
    print(‘SENT: {}’.format(list_Send[1]))
    while not link.available():
    if link.status < 0:
    if link.status == txfer.CRC_ERROR:
    print(‘ERROR: CRC_ERROR’)
    elif link.status == txfer.PAYLOAD_ERROR:
    print(‘ERROR: PAYLOAD_ERROR’)
    elif link.status == txfer.STOP_BYTE_ERROR:
    print(‘ERROR: STOP_BYTE_ERROR’)
    else:
    print(‘ERROR: {}’.format(link.status))
    ##################### Receive Data from Arduino “”#####################
  • ###################################################################*
  • Parse response list*

Number_Value_Received=2 ##### refer to number of data sent from Arduino
list_size_Receive=4*Number_Value_Received
###################################################################
rec_list_ = link.rx_obj(obj_type=type(list_Send),
obj_byte_size=list_size_Receive,
list_format=‘i’)
###################################################################

  • Display the received data*

  • ###################################################################*
    print(‘RCVD: {}’.format(rec_list_[0]))
    print(‘RCVD: {}’.format(rec_list_[1]))
    print(’ ')
    except KeyboardInterrupt:
    try:
    link.close()
    except:
    pass
    except:
    import traceback
    traceback.print_exc()
    try:
    link.close()
    except:
    pass

florianbus:
Arduino “Arduino Send Back data”

Combined 2 examples of Arduino code Receiving Data “uart-rx-data” and Sending Data “uart-tx-data”.

Code Arduino:"Arduino Send Back data"
#include “SerialTransfer.h”
SerialTransfer myTransfer;
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
myTransfer.begin(Serial);
}
void loop()
{
if(myTransfer.available())
{
// send all received data back to Python
for(uint16_t i=0; i < myTransfer.bytesRead; i++)
{
myTransfer.packet.txBuff = myTransfer.packet.rxBuff*;*
_ // Serial1.println(myTransfer.packet.txBuff*);
}
myTransfer.sendData(myTransfer.bytesRead);
}
}[/quote]
> Code Arduino test: Combined 2 examples of Arduino code Receiving Data “uart-rx-data” and Sending Data “uart-tx-data”.
> #include “SerialTransfer.h”
> SerialTransfer myTransfer;
> struct STRUCTReceive {
> char z;
> float y;
> } testStructReceive;
> struct STRUCTTransmit{
> char z;
> float y;
> } testStructTransmit;
> int DataOutputFromRaspberryPi[2]; // refer to number of data sent from Raspberry*
> int DataInputToRaspberryPi[2];
> int SizeDataOutout;
> void setup()
> {
> Serial.begin(115200);
> Serial1.begin(115200);
> myTransfer.begin(Serial);
> }
> void loop()
> {
> ///////////////////////////////////////// Receive DATA from Raspberry //////////////////////////////////////////////////
> if(myTransfer.available())
> {
> // use this variable to keep track of how many
> // bytes we’ve processed from the receive buffer
> uint16_t recSize = 0;
> recSize = myTransfer.rxObj(testStructReceive, recSize);
> //Serial.print(testStructReceive.z);
> //Serial.print(testStructReceive.y);
> // Serial.print(" | ");
> recSize = myTransfer.rxObj(DataOutputFromRaspberryPi, recSize);
> }
> ///////////////////////////////////////// Send DATA to Raspberry //////////////////////////////////////////////////

> DataInputToRaspberryPi[0]=1005;
> DataInputToRaspberryPi[1]=1024;
> // use this variable to keep track of how many
> // bytes we’re stuffing in the transmit buffer
> uint16_t sendSize = 0;
> ///////////////////////////////////////// Stuff buffer with struct
> sendSize = myTransfer.txObj(testStructTransmit, sendSize);
> ///////////////////////////////////////// Stuff buffer with array
> sendSize = myTransfer.txObj(DataInputToRaspberryPi, sendSize);
> ///////////////////////////////////////// Send buffer
> myTransfer.sendData(sendSize);
> }_