No serial data is being passed from arduino to pi or vice versa

I am following this tutorial: https://www.arduino.cc/en/Tutorial/SerialEvent

I copied the exact code, with a slight change in baud rate to 115200.

This is my Python code on my raspberry pi:

if __name__ == "__main"__":
    with serial.Serial('/dev/ttyAMA0', baudrate=115200,rtscts=True, dsrdtr=True, timeout=0.1) as port:
        port.write("Hello.")
        print port.readline() # even tried port.read(6) for this

The problem here is that I cannot get "Hello" to appear on screen on my pi, and I think the Arduino is only reading a part of the signal. Is there anything I can do to fix this?

Thanks!

What do you see in the Serial monitor of the Arduino ? If nothing is getting read by the Arduino then it will, of course, never be sent back to the Pi

By the way, do you realise that every time the Pi opens the serial port the Arduino resets.

There's not enough info for me to know... Are they both using the same baud rate? Can you open them both up at the same time to do some proper diagnostics?

Try hooking up the arduino to the serial monitor first and simulate the pi with your PC.

I had a lot of problems with arduino or pi waiting indefinitely for the partner on the other end - solved this by checking with

if (serial.available) ... on the arduino and

if serial.inWaiting() >= 1 on the pi

I have altered the code a bit using http://forum.arduino.cc/index.php?topic=396450.0 example 3.

I am trying to pass something through the serial monitor but nothing comes out. I commented out the sensor initializations and it works. How can this be fixed?

#include <LiquidCrystal.h>
#include <stdio.h>
#include <stdlib.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;

#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(35, PIN, NEO_GRB + NEO_KHZ800);
#define LONG_RANGE
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char tmp[2] = "";
const int numChars = 500;
char receivedChars[numChars];
int init_index = 0;
int permanent_rgb[3] = {0, 0, 0};
int signal_rgb[3] = {0, 0, 0};
int sensor_location = 0;
bool chk = false;
boolean newData = false;
int strLength = 0;

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  Serial.begin(115200);

  Wire.begin();

  sensor.init();

  sensor.setTimeout(500);
  sensor.setMeasurementTimingBudget(33000);
  sensor.setSignalRateLimit(0.1 * 65536);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);

  sensor.startContinuous();

}

void loop() {
  recvWithStartEndMarkers();
  showNewData();

}

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static int ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        strLength = ndx;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}
void showNewData() {
  if (newData == true) {
    Serial.print(receivedChars);
    newData = false;
  }
}

Is the sensor using your serial bus - probably at a different baud rate?

you could try to hook it up to a soft serial for a try - if the library permits that.

The Sensor is connected to the A4 and A5 pins, using an Analog transmission.

I have also tried a simple Blink program which comes with the IDE. Upon including the sensor initialization block in the setup, the main loop does not run at all.

My guess is that the Arduino is locking itself up getting values from the sensor and ignoring anything else. COuld this be it?

Hi,
Have you written code to just purely send data to the pi?

Did you write this program in stages, getting each stage working before going to the next?

Tom… :slight_smile:

Right now I am only considering Arduino serial communication, so I am testing with the serial monitor.

void setup() {
  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  Serial.begin(115200);
  
  Wire.begin();
  Serial.print("Hello1");
  Serial.print("Hello3");

  sensor.init();
  
  sensor.setTimeout(500);
  sensor.setMeasurementTimingBudget(33000);
  sensor.setSignalRateLimit(0.1 * 65536);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
  
  sensor.startContinuous();

  Serial.print("Hello2");
  
}

In this snippet, only Hello1Hello3 is displayed, but no Hello2

This Python - Arduino demo may help.

...R

Where in your program is the sensor associated with pins A4 and A5 ?