Hello everyone,
I am building a wireless system for my model railway. This system have to send the S88 feedback over the RF24L01+ modules.
I use the MiRF library from Github. The master polls every slave (at this moment only 1) by sending the slave address out. When the right slave received the command, it sends his feedback data back (an array of 0 and 1 => byte data[] = {...}). At the last part it fails.
Sometimes when I changed some stuff in the data array both Serial screen stays blank (The slave only report 'SETUP').
Master:
/*
******************************************
* Trainduino *
* *
*------------> S88 MASTER <--------------*
* *
* V 0.1 BETA *
******************************************
THIS IS A BETA! I'm never resposibly for any damage to your stuff! This version is NOT tested.
(c) Dylan Van Assche (2013 - 2014), producer of the Trainduino serie.
NODE address:
0 BASE
1 - 9 SLAVE
POLLING SYSTEM:
Master sends an slave address, the slave replies with the data.
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int slaveID[] = {1};
void setup(void)
{
// DEBUG
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SETUP");
// Start RF24
Mirf.cePin = 9;
Mirf.csnPin = 10;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv2");
Mirf.setTADDR((byte *)"clie1");
Mirf.payload = sizeof(byte);
Mirf.config();
Serial.println("Beginning ... ");
}
void loop(void)
{
UpdateS88Output();
Poll();
}
void UpdateS88Output()
{
}
void Poll()
{
byte data[Mirf.payload];
Serial.println("POLLING...");
Mirf.send((byte *)&slaveID[0]);
if(!Mirf.isSending() && Mirf.dataReady()){
Serial.println("Got S88 data NOW...");
Mirf.getData(data);
Serial.println("Data print out: /n");
for(int i = 0; i < 17; i++)
{
Serial.println(data[i]);
}
}
delay(1000);
}
Slave:
/*
******************************************
* Trainduino *
* *
*-------------> S88 SLAVE <--------------*
* *
* V 0.1 BETA *
******************************************
THIS IS A BETA! I'm never resposibly for any damage to your stuff! This version is NOT tested.
(c) Dylan Van Assche (2013 - 2014), producer of the Trainduino serie.
NODE address:
0 BASE
1 - 9 SLAVE
POLLING SYSTEM:
Master sends an slave address, the slave replies with the data.
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#define ID 1
byte data[] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
byte slaveID[1] = {ID};
void setup(void)
{
// DEBUG
Serial.begin(9600);
Serial.println("SETUP");
// Start RF24
Mirf.cePin = 9;
Mirf.csnPin = 10;
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.setTADDR((byte *)"serv2");
Mirf.payload = sizeof(byte);
Mirf.config();
}
void loop(void)
{
SendData();
}
void SendData()
{
if(!Mirf.isSending() && Mirf.dataReady()){
Serial.println("Data request received!");
Mirf.getData(slaveID);
if(slaveID[0] = ID)
{
Serial.println("ID confirmed, sending the S88 data back to the master now...");
Mirf.send((byte *)&data);
}
}
}
Somebody who can help me?
Cheers,
Dylan