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

Communication issues between Raspberry and Arduino

Discussion in 'Hyperion General' started by Kirill, 1 December 2016.

  1. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    Hi guys! I recently arrived here, I'm building an ambilight system and I need some help.
    I'm using Raspberry Pi 2 with LibreElec, Arduino Mega, Led strip 2812b EasyCap, and converter from HDMI to AV.
    I already set up the whole system, I'm able to connect to raspberry and take a screenshot on real time. Also I tested separately the strip with a little sketch and is all working.
    The problem comes when I connect the Raspberry and Arduino, I do not know if they are communicating at all, I do not see any response from the Leds. I think it may be because of incorrect sketch, I searched for a couple of them and none of it worked for me.
    I hope that you have the answer for this trouble, I'm so close to this project that I'm really exited but I got stuck on this.
    Thank you in advance!
     
  2. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    609
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino
  3. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    Yes! I used the same sketch changing the normal parameters like: DataPin, LedCount, brightness(not relevant), the BaudRate left the same:9600, and nothing else! I don't know if I have to change something else in function of my setup.
    I understood that the other things were for a direct connection of the led strip with RaspBerry so I ignore thouse steps.
     
  4. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    609
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino
    sure that you read it? you dont need any arduino or something...please read it again...
     
  5. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    Okey, I apologize if I can not understand couple of things, my language is spanish.
    What I could understand was that I had to modify the file .json in the path /storage/.config and add this lines:
    "Gpio": 18,
    "Dmanum": 5,
    "Freq": 800000,
    "Pwmchannel": 0,
    Under "devices". Also I interpreted that I do not need to use Arduino.
    What I could not finish to understand is the part of the converter SPI to ws2812, For what I would need that? If I want the communication to be USB.
    Thank you.
     
  6. billb13

    billb13 New Member

    Messages:
    9
    Hardware:
    RPi3, +Arduino
    If you go on to YouTube and type in search box " ambilight tv " you will find one by the Mad Scientist. He gives a complete tutorial how to make and do the ambilight tv, he has also given the arduino.ino software. This is the set up I'm using and it works for me.. hope it helps. Regards Bill
     
  7. Onedune

    Onedune New Member

    Messages:
    10
    Hardware:
    RPi3, +Arduino
    I think its a problem with the prefix.

    const char prefix[] = {0x41, 0x64, 0x61, 0x00, 0xD4, 0x81}; // Prefix at the start of the transmission
    char buffer[sizeof(prefix)]; // Temporary buffer for receiving the prefix data

    // to calculate your prefix, the first 4 bytes will never change: const char prefix[] = {0x41, 0x64, 0x61, 0x00, this never changes.
    // the next byte is equal to the number of LED - 1 --> (232-1)=231. 231 transformed in HEX. 231 in hex is E7 (use google)
    // the last byte is equal to the XOR value of the calculated value just above and 0x55 (byte just calculated (E7) XORED with 0x55) = B2 use this link http://xor.pw/? and in input 1 put 55 and in input 2 put your HEX value.
    :thumbsup:
     
  8. penfold42

    penfold42 Moderator Developer

    Messages:
    414
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Slight bit pick...

    The 0x00 is the high byte so if you have more than 256 leds it will change.

    The checksum includes this too.
    High byte XOR low byte XOR 0x55
     
  9. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    Okey, I had a crazy month with my job so now I'm resuming the project!
    First of all thank you for answering to this issue. Now I'll post my Hyperion configuration and the Sketch that I'm using.
    That Arduino sketch was downloded from https://hyperion-project.org/wiki/Arduino-sketch-WS2801-to-WS2801 and change the followings lines:

    #include <Adafruit_NeoPixel.h>
    #define ADA_DATAPIN 6 // Datapin
    #define ADA_LEDCOUNT 254 // Number of LEDs used
    #define ADA_BRIGHTNESS 100
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(ADA_LEDCOUNT, ADA_DATAPIN, NEO_RGB + NEO_KHZ800);
    #define MAX_PIXELS 254 // Number of pixels in the string

    I followd all the instructions of https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices and going to the next steps. I was able to
    run the standartest successfully and, like before, take screenshots with Raspberry Pi. When I connect via USB the Raspberry Pi and the Aruino
    and use the sketch that I'm posting I have no reaction in the system, still able to take screenshots but after the "Intro" that is set on the sketch
    nothing happends.

    That thing with prefix, I saw it before in other sketch and also calculated the values, but in this sketch I did't find it.
     

    Attached Files:

  10. penfold42

    penfold42 Moderator Developer

    Messages:
    414
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Ok.... none of this adds up !

    This is good because I know this will never work.

    Option 1) forget the arduino.
    If your Pi is HDMI connected to your screen.
    Use the config.json you have now and connect the led strip directly to the raspberry Pi on gpio pin 18.
    This is how the ws281x device type works.

    Option 2) use the arduino with the sketch you have - I know it well because it's mine.
    While it has a serial interface it's shit and was added because I wanted a separate light inside my Pi as well as the proper strip.
    Ignore the serial capability and instead use the SPI pins MOSI and SCK between the Pi and arduino
    Reconfigure Hyperion to use ws2801 (yes, 2801 it's not a typo)

    Option 3) use a different sketch the supports the adalight serial protocol:
    https://github.com/hyperion-project...assets/firmware/arduino/adalight/adalight.ino
    And reconfigure Hyperion to use the adalight device type
     
  11. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    To use SPI pins do I have to change the sketch?
    So if I understand correctly I connect 3 pins: SPI_MOSI, SPI_MISO and SPI_CLK to the correct ping of Arduino
    and change the type of led. Is that correct?
     
  12. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    I can't understand why if it's your code and it's working for you why for me it's doing nothing! :(
     
  13. penfold42

    penfold42 Moderator Developer

    Messages:
    414
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    For the SPI side you only need MOSI and CLK - miso is not used.

    I think I know the problem - I've never used a MEGA and the pin mapping has changed.


    #define Josh2812_PIXEL_PORT PORTD // Port of the pin the pixels are connected to
    #define Josh2812_PIXEL_DDR DDRD // Port of the pin the pixels are connected to
    #define Josh2812_PIXEL_BIT 4 // Bit of the pin the pixels are connected to


    Change:
    Josh2812_PIXEL_BIT 4
    To:
    Josh2812_PIXEL_BIT 7

    Then use arduino digital pin 38
     
  14. redPanther

    redPanther Moderator Developer

    Messages:
    197
    Hardware:
    RPi1/Zero, RPi2, 32/64bit, +Arduino
    Just a note, when using arduino, set delayAfterConnect in device section to 1500
     
  15. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
    Okey, I'll try that and if it's not working I'll try with Arduino Nano!
     
  16. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
  17. Kirill

    Kirill New Member

    Messages:
    9
    Hardware:
    RPi2, +Arduino
  18. penfold42

    penfold42 Moderator Developer

    Messages:
    414
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    Nano works with fewer leds - I have about 120 running with this sketch.

    On mega with SPI make the change I outlined earlier and use arduino pin 38
    We're changing it so the comments will
    Now be wrong