@TheoL Not only did I put in delays, too, but I put in delays that were based upon the ID (which was stored in NVRAM)! This helped.
caveat: This is probably not accurate be helps to explain the challenges with a large network.
My initial experience with Arduino/nRF24 was using the libraries from TMRh20. Those libraries allowed a node to be a repeater, but only for 6 nodes. The primary node 0, master, only allowed 6 nodes to connect to it. The nodes connected to it also allowed 6 nodes. Subsequent nodes had to go through one of these repeating nodes. But the depth was only 4 deep. The master assigned node IDs if the node didn't already have one; similar to a MAC address.
The master also kept track of the addresses (ARP table?). Addresses were 4 octets (base in the form of D/C/B/A. A node connected directly to the master had an address of 0/0/0/a (where 0/0/0/0 was reserved for the master). A node connected through another node had an address of 0/0/b/a, and so forth.
But what happens is that a parent node has to mange the data from all its child nodes and their child nodes and their child nodes. Thus a node would get so bogged down dealing with this traffic that it din't do its sensor task very well.
It is my belief that MySensors either uses TMRh20's libraries or has developed some aspects based on his initial work. I see that that TMRh20 has a version 2 and I have not experimented with it. I did find that MySensors worked better than version 1.
Thus, my curiosity.
I am also duly impressed at the magnitude of hardware. Currently a nano like device from Aliexperss is US$2-3, nRF24 ~ US$1, power supply ~ US$1.50, power cord ?, case?, sensors!? While the hardware cost is daunting, even with a PCB it's a lot of work building those up. So, yeah, I'm impressed!
-OSD
Just to let you know that I solved the issue.
I found a library where you can control the speed and make sure it get to it's position.
You can find it here: https://github.com/netlabtoolkit/VarSpeedServo
I incorporated it in the Mysensor sketch and it works eventhoug it looks like it only goes like 90 degrees but it's enough for me :
#include <MySensor.h>
#include <SPI.h>
#include <VarSpeedServo.h>
// #include <Servo.h>
#define SERVO_DIGITAL_OUT_PIN 3
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180 // Fine tune your servos max. 0-180
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
#define CHILD_ID 10 // Id of the sensor child
MySensor gw;
MyMessage msg(CHILD_ID, V_DIMMER);
VarSpeedServo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
// Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created Sensor gw(9,10);
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
void setup()
{
// Attach method for incoming messages
gw.begin(incomingMessage);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Servo", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_COVER);
// Request last servo state at startup
gw.request(CHILD_ID, V_DIMMER);
}
void loop()
{
gw.process();
if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
myservo.detach();
attachedServo = false;
}
}
void incomingMessage(const MyMessage &message) {
myservo.attach(SERVO_DIGITAL_OUT_PIN);
attachedServo = true;
if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
int val = message.getInt();
myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val,255,true); // sets the servo position 0-180
// Write some debug info
Serial.print("Servo changed. new state: ");
Serial.println(val);
} else if (message.type==V_UP) {
Serial.println("Servo UP command");
myservo.write(SERVO_MIN,255,true);
gw.send(msg.set(100));
} else if (message.type==V_DOWN) {
Serial.println("Servo DOWN command");
myservo.write(SERVO_MAX,255,true);
gw.send(msg.set(0));
} else if (message.type==V_STOP) {
Serial.println("Servo STOP command");
myservo.detach();
attachedServo = false;
}
timeOfLastChange = millis();
}
Hello,
I want to build this project. But I don't need to power it by batteries. Has anyone the circuit diagram (in FrizIng?)
I have also the problem, that I can't see, on the breadboard picture of this project where the red wire from the battery ends after the connection to the Arduino?
Does it go to the FET and the R7?
Can anyone help me?
@krisztian
Hi krisztian,
the singleLED board - as its name suggests - features only one LED output. If you want to have a setup with multiple LED strips you need to design a board with multiple outputs. I have already designed a board with 4 outputs, but I haven't built it.
In terms of software you need to register multiple sensors in your program like this:
#define numCh 4 //the number of outputs
const byte ledPins[] = {9,6,5,3};
byte ledLevel[numCh];
boolean ledDimWay[numCh];
//in the setup function request the dim levels from the gateway
for(byte i=0; i<numCh; i++) request(i, V_DIMMER);
//in the presentation function register multiple lights
for(byte i=0; i<numCh; i++) present(i, S_DIMMER);
//if you receive a signal, you need to check for the sensor id
setLED(message.sensor, requestedLevel);
//to set the LED level (function: setLED) you need to use the sensor id to determine brightness and pin
//Fade LED to set level
int delta = (level - ledLevel[child]) < 0 ? -1 : 1;
//Write to LED
analogWrite(ledPins[child], map(ledLevel[child],0,100,0,255));
I will probably publish the whole code once I have built and tested the 4LED controller (i call it "MySensors rainbowLED")
Hope I could help you
ThetaDev