Hello,
hoping that somebody can help me. I'm building a f1 steering-wheel and i would like to use the rpmleds and some other leds (DRS, low fuel or something like that) on a wireless connection.
I use 2 arduino nano's and 2 NRF24L01. My first idea was to strip the main program of all necessary stuff except the SHRGBLedbase and the SHRGBLedsNeoPixel.h but that's something i didn't get to work. So i thought (maybe to simple) just to sent whatever the main program is writing to neopixel, numled(j) the r,g,b. ! But somewhere there is something going wrong with the timing of he whole thing.
i already have it sort of working, but its not fast enough. the data witch led should light on or go off isn't accurate enough.
Below my program adjustments. (by the way, everything is copy paste from other program sketches)
Thanks in advance
John Brugman
in the main program i have added this piece in the before setup;
[code]
int j;
int r;
int g;
int b;
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
struct MyData {
byte lednummer;
byte rood;
byte groen;
byte blauw;
};
MyData data;
void resetData()
{
data.lednummer = 0;
data.rood = 0;
data.groen = 0;
data.blauw = 0;
}
this piece in setup;
[/code]
[code]
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
[/code]
this code in the SHRGBLedsNeoPixel.h just after
protected:
void setPixelColor(uint8_t lednumber, uint8_t r, uint8_t g, uint8_t b) {
NeoPixel_strip->setPixelColor(lednumber, r, g, b);
[code]
j=lednumber;
data.lednummer = j;
data.rood = r;
data.groen = g;
data.blauw = b;
radio.write(&data, sizeof(MyData));
[/code]
And this sketch i have in my "reciever"
[code]
#include <Adafruit_NeoPixel.h>
int j;
int r;
int g;
int b;
struct MyData {
byte lednummer;
byte rood;
byte groen;
byte blauw;
};
MyData data;
unsigned long packetsRead = 0;
unsigned long lastUpdate = 0;
int packetsSec = 0;
unsigned long lastRecvTime = 0;
unsigned long drops = 0;
#define PIN 2
#define LEDS 20
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_RGB + NEO_KHZ800);
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
strip.begin();
strip.show();
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
j = data.lednummer;
r = data.rood;
g = data.groen;
b = data.blauw;
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
}
}
strip.setPixelColor(j, r, g, b);
strip.show();
}
[/code]
Hi ! Unfortunately I have no experience with nrf modules , so I can't help directly.
However I can see you are sending data for each single pixel set, that may be quite heavy and it's probably the cause of huge delays and anomaly. I don't know what is the maximum size of the data packets for nrf but it would probably be interesting to group LEDs changes.
Ps : I moved the thread to projects as it's not directly related to simhub features.
ok, but can you tell me how to group led changes?
btw i have checked that the nrf can send 32 bytes
I am making a f1 steering wheel, and i don't wanted any wires to it, so i wanted my leds (20 PL9823 leds on D2)to be wireless connected to simhub and i
got it working with 2x NRF24L01+ and 2x arduino nano. !!!
Added lines in main sketch;
#include "SHSendRadio.h" (just below #define VERSION 'j')
added lines in void setup(){ (just before FlowSerialBegin(19200);)
{
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
And in TAB SHRGBLedsBase.h i added 3 times
data.lednummer = j;
data.rood = r;
data.groen = g;
data.blauw = b;
radio.write(&data, sizeof(MyData));
just below every line that says setPixelColor(j, r, g, b);
(when your leds are in reversed order i think you paste below the setPixelColor(_maxLeds - j - 1, r, g, b); lines, but i haven't tested that!!)
Then i've made a new tab with the name SHSendRadio.h and put this code in there
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
struct MyData {
byte lednummer;
byte rood;
byte groen;
byte blauw;
};
MyData data;
void SendRadio() {
radio.write(&data, sizeof(MyData));
}
Al the above code goes into the nano witch is connected to your computer with simhub
Then for the reciever
load this sketch
#include "SHReadRadio.h"
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, 2, NEO_RGB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
{
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
}
void loop() {
ReadRadio();
strip.setPixelColor(j, r, g, b);
strip.show();
}
make a tab with the name SHReadRadio.h
load this sketch
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int j;
int r;
int g;
int b;
struct MyData {
byte lednummer;
byte rood;
byte groen;
byte blauw;
};
MyData data;
void ReadRadio()
{
{
if ( radio.available() ) {
radio.read(&data, sizeof(MyData));
}
}
j = data.lednummer;
r = data.rood;
g = data.groen;
b = data.blauw;
}
If everything is done right everything should work.. Sketches are in the rar file (20 PL9823 leds on D2)
Interesting project, would possibly like to combine it with a project I am developing. Can we get in contact?
Regards,
Theo
hello, i know you posted this question a long time ago. But if you still have something to ask, be my guest.
John Brugman