Hello, I have been working with the 433Mhz transmitter and receiver modules, I am trying to send a port status over to another board in order for it to use it, and for now I am just trying to send raw port data to make out a hexadecimal or even to try to show the binary status of it. For some reason it doesn't work once I pull some of the pins from high to low or from low to high the data just goes all over the place... so if anyone has an answer please help me out here because I have gone clueless...
I am using the VirtualWire library so if anyone needs a reference to that it is here : Virtual Wire Library
I have been using an arduino UNO clone and an "Original" arduino UNO so the board types on the programmer for me are "Nano" and "Uno"
Receiver code:
#include <VirtualWire.h>
int N1 = 0, N2, Sum;
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(A1);
vw_setup(2000);
vw_rx_start();
}
void loop()
{
Sum = 0;
N1 = 0;
N2 = 0;
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
int i;
digitalWrite(13, true);
Serial.print("Got: ");
int X = 0;
for (i = 0; i < buflen; i++)
{
//Serial.print(buf[i], DEC);
Serial.write(buf[i]);
Serial.print(" ");
}
if(buf[0] > 57 || buf[0] < 48) buf[0] = 48;
if(buf[1] > 57 || buf[1] < 48) buf[1] = 48;
if(buf[2] > 57 || buf[2] < 48) buf[2] = 48;
N1 = (buf[0]-48);
N2 = (buf[1]-48);
if(buf[1] == 0 & buf[2] ==0){
Sum = Sum + N1;
}
else if(buf[2] == 0){
Sum = N1*10;
Sum = Sum +N2;
}
else{
Sum = N1 * 100;
Sum = Sum + N2*10 + (buf[2]-48);
}
Sum = N1 +N2;
Sum = Sum + (buf[2] - 48);
Serial.print("Buf[0] = ");
Serial.println(buf[0]);
Serial.print("Buf[1] = ");
Serial.println(buf[1]);
Serial.print("Buf[2] = ");
Serial.println(buf[2]);
Serial.println("");
Serial.println(Sum, BIN);
digitalWrite(13, false);
}
}
Transmitter code:
#include <VirtualWire.h>
void setup(){
// Serial.begin(9600);
vw_setup(2000);
vw_set_tx_pin(A1);
}
void loop(){
int X = PINB; // Tried using PIND as well...
// char Y = (X);
// X >> 4;
// Serial.println(Y, HEX);
const char msg[4];
sprintf(msg, "%d", X);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
delay(200);
Serial.println(*msg);
// Serial.println(msg);
}