i have spent a while trying to get a RF socket control working on an arduino Uno then it can be passed to my main project on a mega
i tested the code using an uno and wiring using a breadboard and a Raspberry Pi GPIO extension board and eventually got it working 100%
// VARIABLES ------------------------------
// Power Remote Control
// L1=3V,(Yellow) R1=5V,(red) L5 Ground(first purple)
int gpio17 = 2; // L6 Grey Encoded Signal D0
int gpio22 = 3; // L8 Black Encoder Signal D1
int gpio23 = 4; // R8 Purple Encoder Signal D2
int gpio27 = 5; // L7 Orange Encoder Signal D3
int gpio24 = 6; // R9 Brown MODSEL mode select signal (OOK/FSK)
int gpio25 = 7; // R11 Yellow CE modular enable (Output ON/OFF)
// Socket all 1 2 3 4
char* on[] ={"1011", "1111", "1110","1101", "1100"};
char* off[]={"0011", "0111", "0110","0101", "0100"};
void setupPimotePins()
{
// Select the pins used for the encoder K0-K3 data inputs
pinMode(gpio17, OUTPUT);
pinMode(gpio22, OUTPUT);
pinMode(gpio23, OUTPUT);
pinMode(gpio27, OUTPUT);
// Select the signal used to select ASK/FSK
pinMode(gpio24, OUTPUT);
// Select the signal used to enable/disable the modulator
pinMode(gpio25, OUTPUT);
// Disable the modulator by setting CE pin lo
digitalWrite(gpio25, LOW);
// Set the modulator to ASK for On Off Keying
// by setting MODSEL pin lo
digitalWrite(gpio24, LOW);
// Initialise K0-K3 inputs of the encoder to 0000
digitalWrite(gpio17, LOW);
digitalWrite(gpio22, LOW);
digitalWrite(gpio23, LOW);
digitalWrite(gpio27, LOW);
// Give a short delay after setup
delay(500);
}
void state(int state, char* on_or_off[])
{
digitalWrite(gpio27, LOW);
digitalWrite(gpio23, LOW);
digitalWrite(gpio22, LOW);
digitalWrite(gpio17, LOW);
if(on_or_off[state][0] - '0' == 1 )
digitalWrite(gpio27, HIGH);
if(on_or_off[state][1] - '0' == 1 )
digitalWrite(gpio23, HIGH);
if(on_or_off[state][2] - '0' == 1 )
digitalWrite(gpio22, HIGH);
if(on_or_off[state][3] - '0' == 1 )
digitalWrite(gpio17, HIGH);
delay(100);
digitalWrite(gpio25, HIGH);
delay(250);
digitalWrite(gpio25, LOW);
}
void switch_on(int socket)
{
state(socket, on);
}
void switch_off(int socket)
{
state(socket, off);
}
// BEGIN +++++++++++
void setup(){
setupPimotePins();
Serial.begin(9600);
}
void loop(){
Serial.println("on");
switch_on(0);
delay(5000);
Serial.println("off");
switch_off(0);
delay(5000);
}
now using a beadboard and the Raspberry Pi GPIO extension board wired up it is working fine.. so i transferred it minus the breadboard and Raspberry Pi GPIO extension board . and now it wont work
so i transferred it back to the breadboard and it worked
so i removed the breadboard and wired it into the uno double a treble checking the wires also checking connections with multimeter. and nothing it wont work
so it looks like if i use the Board plugged into the Raspberry Pi GPIO extension board connected to the breadboard it works.
without them it wont. what could be causing this??