Hi folks.
I am in the process of designing a wireless MIDI device sending analog sensor info and keypresses for noteon/noteoffs. I am using the Mirf library. The boards | am using are:
1x duemilanove (reciever) and
1xMega2560 (TRANSMITTER)
I am using the cheap black nrf24l01s from China
I have had success sending pot information from the TX to the RX. The codes are below:
// Steve's NRF24l01 sketch sending pot values in an array
// From a Mega2560 to an Arduino Duemilanove.
// This is the Tx end.
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int timer = 100; // The higher the number, the slower the timing.
int potpins[] = {
A0, A1, A2, A3}; // an array of pin numbers to which LEDs are attached
int pinCount = 4; // the number of pins (i.e. the length of the array)int pots;
void setup(){
Serial.begin(9600);
int thisPin;Mirf.cePin = 48; //ce pin on Mega 2560
Mirf.csnPin = 49; //csn pin on Mega 2560
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload =sizeof(pots);
Mirf.config();
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(potpins[thisPin], INPUT);
}
}void loop(){ // loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
int pots=analogRead(potpins[thisPin]);
delay(timer);
// turn the pin off:
//digitalWrite(ledPins[thisPin], LOW);Mirf.setTADDR((byte *)"serv1");
Mirf.send((byte *) &pots);
// Mirf.send((byte *) &butstate);
while(Mirf.isSending()){
}
}
}
Reciever:
// Steve's NRF24l01 using the Mirf Library. Recieving end of
// Pots on Mega2560.
// Serial monitor displays the values of the pots.#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>int pots;
void setup(){
Serial.begin(9600);
//pinMode(led,OUTPUT);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload =sizeof(pots);Mirf.config();
}void loop(){
while(!Mirf.dataReady()){
}
Mirf.getData((byte *) &pots);
// delay(10);
//Mirf.getData((byte *) &butstate);
// digitalWrite(led,butstate);//Serial.println(rate);
//Serial.println (siz);
Serial.println(pots);
delay(10);
}
The serial port reads the sensor info nicely ( I am using 3 pots and one LDR.)
Now I want to send a button press but I am stumped as to how to send the information across wirelessly.
Can anyone help me with this?
I don't know how to set the payload so it accepts more than one array and is it possible to use Mirf.send commands one after the other?
I have tried setting up a button on a digital pin and sending the pin information as a variable set to read digitalRead(buttonpin) but on the RX end I get a stream of noughts followed by a few other numbers. These are not related to me pressing the button...
If anyone could help me to send button presses I would be really grateful.
These modules are really quite good for sending simple info and you have a 32 byte max which is more than enough....
Thanks and kind regards,
Steve.