Troubleshooting LED breath tutorial with X2M200

Discussion in 'Respiration Sensor' started by Lena Saleh, Feb 21, 2017.

  1. Lena Saleh

    Lena Saleh New Member

    Hi there,

    I have tried everything and have hooked up the exact components and code from Oyvinds tutorial of the breath lighting the LEDs.

    The Arduino Zero radar distance code returns distance data but led fader code only has green light flashing on Xethru radar but LED's do nothing. We're sure that it's connected to the right port because we tested it.

    We’ve connected to arduino zero, tried the zero data distance sensor, data is received so we know it is hooked up correctly, but led breath code doesn’t work and we’ve tried all three from the github (https://github.com/oyvdahl/xethru-arduino-radar) and none of the leds faded on any of them. We switched led to 3, 5, 6 just to double check but doesn’t work either. help! IMG_2594.JPG IMG_2600.JPG
     

    Attached Files:

  2. Øyvind Nydal Dahl

    Øyvind Nydal Dahl New Member

    Does the red LED turn on?
    What about the other LEDs - on or off?

    In the loop() function you have:
    float movement = radar.get_resp_movement();

    Try to print this value and let me know what you're getting.

    Best,
    Oyvind
     
  3. Lena Saleh

    Lena Saleh New Member

    Hi Oyvind,

    This is the code that I uploaded and still not receiving any data in the serial port. I've checked multiple times that the four wires are connected correctly to 3.3v, GND and TX/RX on the Arduino Zero, but still no response.

    Also, the LED's do nothing.

    #include <XeThruRadar.h>


    //LED pins
    const int red_pin = 3;
    const int green_pin = 4;
    const int blue_pin = 5;

    XeThruRadar radar;

    void setup() {
    Serial.begin(115200);
    pinMode(green_pin, OUTPUT);
    pinMode(blue_pin, OUTPUT);
    pinMode(red_pin, OUTPUT);

    radar.reset_module();
    radar.load_respiration_app();
    radar.execute_app();

    //Set initializing color
    setColor(255, 0, 255, 1.0);
    }


    void loop() {
    float movement = radar.get_resp_movement();
    Serial.println(movement);
    //Movement is usually between -1 and 1, so move it to 0 to 1 instead:
    float brightness = movement + 1.0;
    brightness += 1.0;
    brightness = brightness/2.0;

    setColor(0, 0, 255, brightness);
    }



    void setColor(int red, int green, int blue, float brightness)
    {
    //Make sure brightness is between 0 and 1:
    if (brightness > 1.0)
    brightness = 1.0;
    else if (brightness < 0.0)
    brightness = 0.0;

    //Set the brightness of each color
    analogWrite(red_pin, 255 - red * brightness);
    analogWrite(green_pin, 255 - green * brightness);
    analogWrite(blue_pin, 255 - blue * brightness);
    }

    void blink_red() {
    while(1) {
    setColor(255, 0, 0, 1.0);
    delay(500);
    setColor(0, 0, 0, 0.0);
    delay(500);
    }
    }

    void blink_green() {
    while(1) {
    setColor(0, 255, 0, 1.0);
    delay(500);
    setColor(0, 0, 0, 0.0);
    delay(500);
    }
    }

    void blink_blue() {
    while(1) {
    setColor(0, 0, 255, 1.0);
    delay(500);
    setColor(0, 0, 0, 0.0);
    delay(500);
    }
    }


    IMG_3759.JPG
     

    Attached Files:

  4. Øyvind Nydal Dahl

    Øyvind Nydal Dahl New Member

    Hey Lena,

    I think the TX and RX pins on the Arduino are connected to Serial1 not Serial. So that's one thing you'll need to change in the code.

    You're using the library that I wrote, right? In that case you need to go into the XeThruRadar.cpp file and change Serial to Serial1.

    And to be able to send debug messages to the computer without messing up the communication with the radar board, you need to use the SerialUSB and connect a cable from it to the computer to be able to receive debug messages. Where you added Serial.println, you need to use SerialUSB.println

    This should get debugging working at least. Then it's much easier to figure out any other errors (if there are more).

    Best,
    Oyvind
     
  5. kiba

    kiba New Member

    Hello!

    I am using the XeThru Radar Sensor for a heath care project. This is my first time working with an Arduino and have spent the past week trying to figure this out on my own but I still have not been able to get to get the data from the sensor to my computer. I have followed the other forum posts here and on the Arduino website but my knowledge of hardware is non-existent so I have made little progress on my own and am asking for help directly. I am using your CPP library from the tutorial.

    Here is my overall configuration:

    Hardware -
    Arduino Mega 2560
    X2M200

    Environment -
    Arduino IDE 1.8.1

    Setup -
    Voltage to sensor's pin 1
    Ground to sensor's pin 2
    Serial1 Rx to sensor's pin 3
    Serial1 Tx to sensor's pin 4

    During the setup function everything is fine through radar.init() and I have altered the library to use Serial1 instead of default Serial. There seems to be an error after radar.reset_module( ) because my debug logs are not appearing afterwards and the loop function is not initializing. If I remove all the radar method calls in setup I get the first "loop" in debug channel and then it obviously fails on the radar method call in the loop because it has not been initialized. Despite all of this, the radar will blink every once in a while and sometimes continuously even though the program does not seem to be running. I have removed the LEDs for simplicities sake so I do not know if that affects how the program runs, it appears to me that the failures are before they would even be used.

    Please let me know if you need more details I have uploaded pictures here https://goo.gl/photos/QGXGfJQyTudMsKn69

    Code:
    #include <XeThruRadar.h>
    
    //LED pins
    const int red_pin = 5;
    const int green_pin = 6;
    const int blue_pin = 7;
    
    XeThruRadar radar;
    
    // Help variables
    int error_count = 0;
    
    void setup() {
      //XeThruSensor
      Serial1.begin(115200);
      while(!Serial1); 
    
      //Debugging Channel
      Serial.begin(9600);
      while(!Serial);
    
      radar.init();
      Serial.println("radar initiated");
    
    
    
      pinMode(red_pin, OUTPUT);
      pinMode(green_pin, OUTPUT);
      pinMode(blue_pin, OUTPUT);
    
      radar.reset_module();
      radar.load_respiration_app();
      radar.execute_app();
    
      Serial.println("post radar test");
    
      //Set initializing color
      setColor(255, 0, 255, 1.0);
    }
    
    
    void loop() {
      Serial.println("loop");
      float movement = radar.get_resp_movement();
    
    
      Serial.println(movement);
    
    //  If it returns -99.0, that means it did not receive a proper measurement
      if (movement == -99.0) {
         error_count++;
         if (error_count > 5) {
           setColor(255, 0, 0, 1.0);
          
           //Reset error counter
           error_count = 0;
         }
      }
      else {
        //Reset error counter
        error_count = 0;
        
        //Movement is usually between -1 and 1, so move it to 0 to 1 instead:
        float brightness = movement + 1.0;
        brightness += 1.0;
        brightness = brightness/2.0;
        
        setColor(0, 0, 255, brightness);
      }
    }
    
    
    void setColor(int red, int green, int blue, float brightness)
    {
      //Make sure brightness is between 0 and 1:
      if (brightness > 1.0)
        brightness = 1.0;
      else if (brightness < 0.0)
        brightness = 0.0;
    
      //Set the brightness of each color
    
      analogWrite(red_pin, 255 - red * brightness);
      analogWrite(green_pin, 255 - green * brightness);
      analogWrite(blue_pin, 255 - blue * brightness);
    
    }
    
     
  6. Øyvind Nydal Dahl

    Øyvind Nydal Dahl New Member

    Hey kiba,

    Isn't the Arduino Mega running with 5V? The radar uses 3.3V, so you would need a level converter.

    Best,
    Oyvind
     
  7. kiba

    kiba New Member

    Hi Øyvind,

    Thank you for your quick response!

    I have the power connected to the 3.3V output but after researching your comment I learned that the pins themselves are running on 5V. After following your advice I am now receiving data, however it is a constant stream of -99.00 error codes. Sorry for the simple mistake, I can coming from web development and this is my first experience with electronics. Thank you for your help I will try to figure the rest out from here.

    Cheers,
    Kiba
     
  8. Øyvind Nydal Dahl

    Øyvind Nydal Dahl New Member

    Hey Kiba,

    A constant stream of -99 is a good sign. That means the communication is working. I wrote the library two years ago to get a simple example up and running. But looking through it now, I see that some functions could use an update.

    I've started updating the library to reduce the amount of -99's and to make it easier to debug if it's not working like you want. Hopefully, I'll have it ready by the end of next week.

    Best,
    Oyvind
     
    Lena Saleh likes this.
  9. Øyvind Nydal Dahl

    Øyvind Nydal Dahl New Member

    Olav Liseth likes this.