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