Serial communicatoin problem using Onion and Arduino

Dears,
After several weeks of struggling I would like to seek help from the talented people in this forum. I have an Onion Omega 2+ microcontroller on an Arduino Dock 2 and an ethernet shield. I am using python and pyserial to interface between the arduino board and the OS on the Onion, but the communication is very flawed. So flawed to be honest, that only one or two characters are going through and I can only see some indicatoin of messages while using the screen command to troubleshoot. I tried to write a message to the Onions /dev/ttyS1 with echo, nothing came up while I was screening it. I also put serial message into a loop on Arduino, and I got about 5 characters on the screen of the Onion. Below is the code for the Arduino Board:

#include <cactus_io_AM2302.h>;
    #include <stdio.h>
    
    // defines pins numbers
    const int trigPin = 9;
    const int echoPin = 10;
    
   #define AM2302_PIN 7
   AM2302 dht(AM2302_PIN);

    
    // defines variables
    long duration;
    int distance;
    int del;
    
    void setup() {
    Serial.begin(9600); // Starts the serial communication
    del=1;
    }







// void called 1
    void read_ultrasonic_sensor(){
    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    delayMicroseconds(1000);
      // Clears the trigPin
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    //String D="read_ultrasonic_sensor:"+String(distance);
    Serial.println(distance + "*");
    //Serial.println(distance);
    // Clears the trigPin
    digitalWrite(trigPin, LOW);
    
    }

    void read_temperature_sensor(){
     dht.begin();
     delay(2500);
     dht.readHumidity();
     dht.readTemperature();
     Serial.print(dht.humidity);
     Serial.print(" %");
     Serial.print(dht.temperature_C);
     Serial.println(" C*");
    }



    
    void loop() {
      if (Serial.available() >0) {
      String voidname;
      del=del+1;
      if(del>10){ 
      voidname= Serial.readString();  //gets one byte from serial buffer
      del=1;
      }
      Serial.print("#");

      if (voidname=="read_ultrasonic_sensor"){
        read_ultrasonic_sensor();
        }
      if (voidname=="read_temperature_sensor"){
        read_temperature_sensor();
        }
      }
    }

And the output of screen /dev/ttyS1 9600 is the following after 2 minutes:

###########

My expectation would have been a rolling mass of “#” signals.

Thank you very much for your help in advance!
Regards,
Cow

I have an Onion Omega 2+ microcontroller on an Arduino Dock 2

What the heck is an "Arduino Dock 2"?

I am using python and pyserial to interface between the arduino board and the OS on the Onion

What the hell does "to interface" mean? How are you using python on the Arduino?

Most of your comments are either obvious to even a clueless newbie or wrong. Get rid of the useless ones, and fix the ones that are wrong (which probably will make you investigate the functions and figure out what is wrong with your code).

      String voidname;

What do you call digitalRead()? An int, because it returns an int?

They are FUNCTIONS, not VOIDS.

Hi,
Thanks for taking the time to compile your reply, regardless of the tone it has. To answer your questions which are apparently not obvious to anyone other than me, the arduino dock is an Arduino Uno R3 with a slot for an Onion Omega microcontroller. By saying "to interface" I meant "communicate between the Arduino Uno R3 board and the Onion Omega microcontroller". Python is being used on the operating system of the Onion Omega, which runs LEDE.
I am sorry for naming my string variable something that has "void" in its name. I am using voids because in my understanding a function has a return value, however what I am doing produces no returns in the code.

Thank you for your answer again!
Regards,
Cow

I am using voids because in my understanding a function has a return value

A function has a return TYPE. That type can be void.

A function does not have to return a VALUE.

the arduino dock is an Arduino Uno R3 with a slot for an Onion Omega microcontroller.

I still don't understand, and none of your links work.

Dear PaulS,
I have not linked anything in my previous posts, that might be why you are unable to open any links. The issue is that when I send a value over serial, the receiving end sees incomplete- or no data whatsoever. I am not sure why.
I have also highlighted that the microcontroller could talk to itself using serial, and that is also seemingly misbehaving, as in not being able to monitor its own serial port, however it is able to send data over to the Arduino board without any issue. So currently I am not sure if improper usage of serial communication is the issue or firmware issue on the Arduino board, OR some issue with the microcontroller.

Regards,
Cow

Actioncow:
So currently I am not sure if improper usage of serial communication is the issue or firmware issue on the Arduino board, OR some issue with the microcontroller.

Don't know.

I doubt many people have the Onion or the Arduino Dock 2.

You have the hardware, so you need to figure it out.

.

Dears,
Thanks for the input, I'll try to figure it out then.
Regards,
Cow

If it was me, I would start with a very simple sketch for the Arduino.
Also, avoid using String in Arduino.
Use, character byte arrays., e.g. char bytes[20]

I have not linked anything in my previous posts

That was a hint.

This Python - Arduino demo may be of interest.

Also see Serial Input Basics - simple reliable ways to receive data.

...R

Dear Robin2,
Thank you very much fo rth ecomprehensive guide on how to receive data on Arduino. However sadly enough I have the issue the other way around. My micro controller has issues reading the arduinos replies from serial. I will check and most probably implement the codes you have posted, so I thank you very much for those.
Regards,
Cow

Actioncow:
Thank you very much fo rth ecomprehensive guide on how to receive data on Arduino. However sadly enough I have the issue the other way around. My micro controller has issues reading the arduinos replies from serial.

Maybe I misunderstood but I got the impression that your "micro controller" is using Python - hence my link to my Python demo.

Is the micro-controller also using Linux?

...R

Dear Robin2,
Apologies, totally missed the files at the bottom of your message in the python tutorial. Checking them now. As for the misunderstanding, I call the Onion Omega 2+ as "microcontroller" and the arduino dock as the "Arduino". Apologies.
Regards,
Cow

Dear Robin2,
I have checked your code for python and Arduino at the port you linked, downloaded the codes, and uploaded them to the respective devices without modification, although I have no leds nor servos. I ran the code and the python on the Omega was just waiting for the ready signal from arduino. I reuploaded the arduino code to reboot it, and it wrote its ready string to serial, but still nothing happened.
I am getting more desperate thinking there is some hardware issue with the Omega.
Regards,
Cow

Post the two programs that YOU have uploaded to your two devices. And tell us in as much detail as possible what heppens when you run the programs.

You did not answer my earlier question about whether your micro controller uses Linux.

A link to a webpage that provdes background info about the micro controller would be a big help.

…R

Dear Robin2,
the two programs uploaded to the devices are the exact same files that you have put into the tutorial (http://forum.arduino.cc/index.php?topic=225329.msg1810764#msg1810764).

The following is what I am doing and what happens:

  • I open an SSH conenction to the Omega Onion 2 microcontroller that is on the Arduino dock, and start the python code that is the exact code you attached to the post above (ComArduino2.py).
  • I open another SSH connection and run screen /dev/ttyS1 9600 to monitor the serial communcation.
  • I upload the code onto the arduino board that is the exact same code that you attached to the above mentioned post (ArduinoPC2.ino).
  • When the upload completes, the Arduino board posts “” to the serial monitor.
  • The python program on the Omega keeps doing nothing whatsoever.
  • Literally nothing is happening, and nothing else is visible on the serial monitor.

The Onion Omega 2+ that is running LEDE (a linux distribution):Omega2+ – Onion
The arduino dock it is put onto:https://onion.io/store/arduino-dock-r2/

Thanks in advance for your reply!

Actioncow:
The Onion Omega 2+ that is running LEDE (a linux distribution):Omega2+ – Onion
The arduino dock it is put onto:https://onion.io/store/arduino-dock-r2/

Thanks in advance for your reply!

I have looked briefly at those two links and I just don't know enough about those devices to have any more advice. Sorry.

Perhaps the developers of the devices have their own help Forum?

...R

Dear Robin2,
They do have their own forum however I did not receive a single answer :confused:
I have given up serial communication, and decided to transfer data somehow differently. I am failing so far since I do not have an ethernet shield. I probably going to have to result to buying a proper arduino board.
Thanks for all your help!

Actioncow:
I probably going to have to result to buying a proper arduino board.

Not a bad idea :slight_smile:

If you need WiFi the various ESP8266 modules seem to be well supported - and boards such as the NodeMCU

...R

Actioncow:
Dear Robin2,
the two programs uploaded to the devices are the exact same files that you have put into the tutorial (http://forum.arduino.cc/index.php?topic=225329.msg1810764#msg1810764).

The following is what I am doing and what happens:

  • I open an SSH conenction to the Omega Onion 2 microcontroller that is on the Arduino dock, and start the python code that is the exact code you attached to the post above (ComArduino2.py).
  • I open another SSH connection and run screen /dev/ttyS1 9600 to monitor the serial communcation.
  • I upload the code onto the arduino board that is the exact same code that you attached to the above mentioned post (ArduinoPC2.ino).
  • When the upload completes, the Arduino board posts “” to the serial monitor.
  • The python program on the Omega keeps doing nothing whatsoever.
  • Literally nothing is happening, and nothing else is visible on the serial monitor.

The Onion Omega 2+ that is running LEDE (a linux distribution):Omega2+ – Onion
The arduino dock it is put onto:https://onion.io/store/arduino-dock-r2/

Thanks in advance for your reply!

If I am understanding this correctly, the Omega 2+ is sending bytes to the Arduino Dock and the Arduino Dock reads the bytes and outputs to the Serial Monitor.
I would be interested in what happens if you take the Arduino Dock out of the picture.

Does the Onion Omega 2+ have a way to output to just a serial port?

.