G+_Newton Robinson Posted April 16, 2018 Share Posted April 16, 2018 I need help with a programming problem. I have created an LED matrix that is 50x36 WS2812B LED's. 6 strings of 50x6. I control each of the 50x6 matrix with an Arduino Nano. This works well using Jinx! under Windows. You can see the display in my previous posts. What I want to do is record the Jinx! output, copy it to a Raspberry PI, then open the 6 serial devices connected to the Raspberry PI and send the data. I believe the Raspberry Pi can to this because there will be no calculations. The following is the code on the Arduino that works with Jinx!: ---------------------------------------------------------------------------------------------------------------- // Glediator script for WS2812B LEDs // Found at: https://forum.pjrc.com/threads/32861-Glediator-Jinx-with-Teensy-3-2-and-WS2812b // User mortonkopf 02-09-2016 @ 4:57 PM // Tested with JINX! // Set NUM_LEDS to the number of LEDS in the string your are controlling. // Set dataline to the Arduino PIN you are going to use. // You must install the FastLED Library. // I have tested wint Arduino UNO R2 and R3. Arduino Mega 2560 R3 and SainSmart (Not sure which version) #include "FastLED.h" #define NUM_LEDS 300 // Set the number of LEDs const int dataline = 6; // Arduino PIN CRGB leds[NUM_LEDS]; void setup() { Serial.begin(115200); LEDS.addLeds(leds, NUM_LEDS); } int serialGlediator() { while(!Serial.available()) {} return Serial.read(); } void loop() { while(serialGlediator() != 1) {} for(int i=0; i < NUM_LEDS; i++) { leds.r = serialGlediator(); leds.g = serialGlediator(); leds.b = serialGlediator(); } FastSPI_LED.show(); while(serialGlediator() != 1) {} //delay(100); } ---------------------------------------------------------------------------------------------------------------- I have confirmed that when I plug the Arduino into the Raspberry Pi, the /dev/ttyUSB0 is created. I then did a chmod o+rw /dev/ttyUSB0. What I think I'm doing. Opening /dev/ttyUSB0 for read write 8N1 for raw output. I also think that what I need to do is send 900 bytes to the Arduino. I then expect the code on the Arduino to display. The program seem to runs successfully, but nothing is displayed on the LED sign. If someone can give me some pointers on the following code: ---------------------------------------------------------------------------------------------------------------------- #include #include #include #include #include #include #include #include using namespace std; int main() { char cmd[900]; int USB = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY); if(USB < 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } struct termios tty; memset(&tty, 0, sizeof tty); if(tcgetattr(USB, &tty) != 0) { perror("tcgerattr "); } cfsetospeed(&tty, B115200); cfsetispeed(&tty, B115200); tty.c_cflag &= ~PARENB; //Make 8N1 tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CSIZE; tty.c_cflag |= CS8; tty.c_cflag &= ~CRTSCTS; //No flow control tty.c_lflag = 0; //No signaling chars, no echo, no canonical processing tty.c_oflag = 0; //No remapping, no delays tty.c_cc[VMIN] = 5; //0.5 seconds read timeout tty.c_cflag |= CREAD | CLOCAL; //Turn on READ & ignore ctrl lines tty.c_iflag &= ~(IXON | IXOFF | IXANY); //Turn off s/w flow ctrl tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //Make raw tty.c_oflag &= ~OPOST; //Make raw tcflush(USB, TCIFLUSH); // Flush port, then aplies attributes if(tcsetattr(USB, TCSANOW, &tty) != 0) { //cout << "Error " << errno << "from tcsetattr" << endl; } //**Write** for(int i=0; i < 900; i++) { cmd='a'; } int n_written = write(USB, cmd, 900); cout << n_written << endl; cout << cmd << endl; close(USB); } Link to comment Share on other sites More sharing options...
Recommended Posts