1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

RPi + Other Software RPi3 + Arduino Pro mini / ATMega2560 + WS2812: slow updates

Discussion in 'Software Support' started by pyr0ball, 8 October 2018.

  1. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    I've been poking around in the threads for a while and solved most of my setup issues doing so. I'm at the point where I'm still just testing Hyperion's direct control over the WS2812 strip before I start diving into the video capture portion of the setup. I'm trying with two different arduinos and getting the same behavior from both, so I can verify the source of the problem. 99% of the testing I'm doing is using direct terminal commands over ssh rather than using the HyperCon software as I tend to lean toward CLI stuff anyway.

    Testing setup:
    • Raspberry Pi 3 running Raspbian Stretch Lite (who needs a GUI on there anyway?)
    • Arduino Pro mini 16mhz 5v // Arduino Mega 2560
    • WS2812b LED strip (currently utilizing only 10 LED's for testing purposes)
    Raspberry pi config.txt parameters set for this project:
    Code:
    # Disable Bluetooth
    dtoverlay=pi3-disable-bt
    
    # neopixel arduino setup
    init_uart_clock=14745600
    enable_uart=1
    dtparam=spi=on
    hdmi_force_hotplug=1
    hdmi_force_edid_audio=1
    core_freq=250
    Arduino sketch used:
    Code:
    #include "FastLED.h"
    
    // How many leds in your strip?
    #define NUM_LEDS 10
    
    // For led chips like Neopixels, which have a data line, ground, and power, you just
    // need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
    // ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
    #define DATA_PIN 10
    //#define CLOCK_PIN 13
    
    #define COLOR_ORDER GRB
    
    // Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
    uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
    
    // Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
    #define serialRate 115200
    
    
    // Define the array of leds
    CRGB leds[NUM_LEDS];
    
    void setup() { 
          // Uncomment/edit one of the following lines for your leds arrangement.
          // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
             FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
          // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
          
          // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
    
          // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
          // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
          
            // initial RGB flash
            LEDS.showColor(CRGB(255, 0, 0));
            delay(500);
            LEDS.showColor(CRGB(0, 255, 0));
            delay(500);
            LEDS.showColor(CRGB(0, 0, 255));
            delay(500);
            LEDS.showColor(CRGB(0, 0, 0));
            
            Serial.begin(serialRate);
            Serial.print("Ada\n"); // Send "Magic Word" string to host
    
    }
    
    void loop() { 
      // wait for first byte of Magic Word
      for(i = 0; i < sizeof prefix; ++i) {
        waitLoop: while (!Serial.available()) ;;
        // Check next byte in Magic Word
        if(prefix[i] == Serial.read()) continue;
        // otherwise, start over
        i = 0;
        goto waitLoop;
      }
      
      // Hi, Lo, Checksum
      
      while (!Serial.available()) ;;
      hi=Serial.read();
      while (!Serial.available()) ;;
      lo=Serial.read();
      while (!Serial.available()) ;;
      chk=Serial.read();
      
      // if checksum does not match go back to wait
      if (chk != (hi ^ lo ^ 0x55))
      {
        i=0;
        goto waitLoop;
      }
      
      memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
      // read the transmission data and set LED values
      for (uint8_t i = 0; i < NUM_LEDS; i++) {
        byte r, g, b;    
        while(!Serial.available());
        r = Serial.read();
        while(!Serial.available());
        g = Serial.read();
        while(!Serial.available());
        b = Serial.read();
        leds[i].r = r;
        leds[i].g = g;
        leds[i].b = b;
      }
      // shows new values
     FastLED.show();
    }
    hyperion config (devices section only as the rest is currently default generated by HyperCon
    Code:
     // DEVICE CONFIGURATION
            "device" :
            {
                    "name"       : "Test",
                    "type"       : "adalight",
                    "output"     : "/dev/ttyAMA0",
                    "rate"     : 115200,
                    "delayAfterConnect"     : 0,
                    "colorOrder" : "grb",
                    "leds"  : 15
            },
    
    Things that are working:
    • Test light pattern upon arduino boot up (both behave the same)
    • Rainbow swirl upon hyperion service start
      • When arduino is configured for the test number of LED's of 10 AND when running at 115200 baud
    • Serial connection over GPIO UART ttyAMA0 @ 115200 baud
    • Serial connection over ttyUSB0 @ 115200 baud (only tested using ATMega2560)
    What's not working:
    • Serial control at the recommended 460800 baud on any interface
    • Attempted control over direct SPI using a 1k ohm resistor, GPIO18
    • Rainbow Swirl upon hyperion service start
      • When Ardiuno is configured for full strip use (108 LED's) and it's running at 115200 b, the led updates come in around 5-7 "fps"

    So the big problem I'm seeing is that when I set the arduino sketch to use 108 LED's as I expect to need on my TV, the color transitions become very "choppy" regardless if hyperion is configured to use 108 LED's or just the original 10 LED's.

    I'm pretty sure this has to do with the serial communication rate as I'm thus far unable to get my RPi to work over anything higher than 115200 baud. As you can see in the config.txt above I did try to set the serial clock rate higher, but I'm not sure if that's actually working, or how to check the current clock rate.

    Any help would be apprecaited!
     
  2. Akriss

    Akriss Active Member

    Messages:
    377
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
  3. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
  4. Akriss

    Akriss Active Member

    Messages:
    377
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Only if its a ftdi based board.

    else I try higher baud rates till I start seeing strange led behavior, then I dial back the baud rate a tad.
     
  5. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Well that's kinda the point I'm getting at. Hyperion seems to be unable to communicate with either the Pro Mini or the Mega2560 at all at 460800. I'm using exactly the same sketch in each instance, just changing the serial rate in the sketch and in hyperion config. The arduino still shows the boot-up test pattern on the LED's but not hyperion's input.

    Both arduinos work when using 115200, albeit with slow refresh rate when I have them configured for 108 LED's

    To clarify, I'm using the UART pins on the RPi direct to TX0/RX0 on the Mega, and obviously the Pro only has the one serial
     
  6. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    OK Update,

    I used the new sketch running at 115200b and it's definitely faster than the old one, but still visibly slow refresh rate
     
  7. Akriss

    Akriss Active Member

    Messages:
    377
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Hmm, sorry I missed the uart bit, thought it was via usb. I have no real experience with arduino communications to and from Pi via gpio's.
     
  8. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    well I mean, worst case I could use the USB UART I'm using to program the Mini. It's got a Silicone Labs CP2104 (datasheet says max of 2mbps), but I'd rather cut out the middle-man if possible
     
  9. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    OK I just tried with the Sil USB UART adapter and 'I'm getting exactly the same behavior.

    Do I need to adjust the Pi's UART clock differently maybe?
     
  10. Akriss

    Akriss Active Member

    Messages:
    377
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
  11. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Thanks for the link, unfortunately everything covered in that article I'm past, and it doesn't address increasing baud rates above 115200. A problem I'm running into is I'm not sure how to get serial feedback from the arduino as the adalight sketch doesnt seem to have any serialout for feedback or I could test the connection directly with minicom
     
  12. Akriss

    Akriss Active Member

    Messages:
    377
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
  13. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Was trying to manually set the default baud rate using some of the stuf in this thread: https://www.raspberrypi.org/forums/viewtopic.php?t=73673

    I'm gonna try grabbing the latest start.elf as suggested in that last post and see if that makes a difference.

    Also I need to find a testing sketch to try something that will echo me back when I send it stuff
     
  14. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Update, got ahold of a sketch with a serial print command on boot, tested at 57600 / 115200 / 460800, fun thing, the two slower baud rates worked, but the 460800 came out garbled, so something is definitely wrong with my pi and it's ability to work at higher baud rates, just need to trace that now.

    I'm gonna try a different RPi image and see if I get different results
     
  15. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Well I did get different results, but still not getting output I expect. Pic on the left is the raspbian Stretch image, one on the right is NOOBS Jessie using same sketch and 460800 baud. Expected to see it say "hello world":

    upload_2018-10-12_13-50-55.png
     
  16. pyr0ball

    pyr0ball New Member

    Messages:
    11
    Hardware:
    RPi1/Zero, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    I'm gonna try adding a level shifter, see if that helps.

    edit: No luck. I was able to get feedback from my atmega2560 running at 460800 on it's USB, but not the UART pins.
    I think I've narrowed it down to two possible bottlenecks: UART on the Pi is definitely not liking 460800 baud, and it's possible the Atmega328p can't go above 115200. I'm gonna grab an Atmega32U4 and try with that

    Edit2: Ok finally found something. I'm checking the UART input using an app called minicom. I've got it set to 460800 baud in it's settings, and I tried this with a sketch running at 115200 baud, and it came in correctly, which means the UART port will not go above 115200 even when set to do so.
    upload_2018-10-12_15-9-36.png
    upload_2018-10-12_15-9-53.png
     
    Last edited: 13 October 2018