i try to control WS2812B leds with arduino uno via serial port.
Grasshopper/Firefly writes a string value to the serial port.
Grasshopper/Firefly node setup.
Sketch to control leds via Serial.parseInt. and the FastLED library.
#include "FastLED.h"
#define NUM_LEDS 57
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
void setup(){
Serial.begin(9600);
Serial.setTimeout(10);
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
}
void loop() {
while (Serial.available() > 0){
int hue = Serial.parseInt();
int sat = Serial.parseInt();
int val = Serial.parseInt();
int pos = Serial.parseInt();
if(Serial.read()=='\n'){
leds[pos].setHSV(hue,sat,val);
}
FastLED.show();
}
}
It works but unfortunatly some data get lost if i use some sliders in grasshopper to fast.
My guess is that the tight timing cause this problem Interrupt problems · FastLED/FastLED Wiki · GitHub so the solution schould be leds with a clock pin like APA102.
My questions are.
1.Is my guessing and the provided solution correct?
2.Is there a better way to use the serialport without the timing problem (If this is really the problem)?
My next tries will be to use loops for animation and use serialport just to switch between these animations.
1.Is my guessing and the provided solution correct?
Maybe. Maybe not. It would depend on exactly what string is being sent. The parseInt() function IS a blocking function, so it could interfere with timing, IF it is called before the delimiter that marks the end of the int being parsed has arrived. That assumes that there actually IS a delimiter marking the end of the last one.
i will try to use the examples provided in your link.
Is there a way to see what kind of message is send by grasshopper because if the port is open from grasshopper i cant use the serialmonitor from arduino.?
blh64
thanks for the link but in my first post there is already this link. But because i am a absolut beginner there could be so much faults not only the timing so i have to try to eliminate one problem after the other step by step and im a very happy that i get what i want.
i will try to use the examples provided in your link.
Is there a way to see what kind of message is send by grasshopper because if the port is open from grasshopper i cant use the serialmonitor from arduino.?
The easiest way for that would to use SoftwareSerial and create a 2nd port to broadcast out what came in (or have the grasshopper data come in on SoftwareSerial and spit it back out to the terminal). Of course, this takes more time and could mess up the timing even more.