Hi. I want to control a motor with pwm provided by the msp430g2553 and the energia analogWrite function, and pass it values remotely using the Anaren AirBooster pack. Transmitting launchpad, uses the followng code.
unsigned char txData[4];//data to transmit
unsigned int IncomingNumber =0;
#include <SPI.h>
#include <AIR430BoostETSI.h>
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
establishContact();
Radio.begin(0x01, CHANNEL_1, POWER_MAX);
Serial.println("Transmitter");
}
void loop()
{
if (Serial.available()>0)
{
IncomingNumber=Serial.read();
memcpy(txData,(char*)&IncomingNumber,3);
Radio.transmit(ADDRESS_BROADCAST, txData, 4);
Serial.print((char*)txData);
//delay(1000);
}
}
void establishContact()
{
while (Serial.available() <= 0)
{
Serial.println("TX TX TX"); // send an initial string
delay(300);
}
}
I use a serial connection from my pc to the transmitter and send the pwm value (0-255) which is transmitted as txData. So far so good. When I use the following code to receive the pwm value I have not been able to convert the rxData from the unsigned char rxData into a usable value for analogWrite(). Every method I use gives me the error "invalid conversion from 'unsigned char*' to 'const char*' [-fpermissive]". The pwm works ok. The radios are communicating ok. The problem lies with the format of the transmitted/received data. For instance if I type"123" at the transmitter it will be received as 1 and 2 and 3 on different lines and in raw bytes. I need to be able to pass "123" to analogWrite() at the receiver. So outVal needs to be "123"
#include <SPI.h>
#include <AIR430BoostETSI.h>
// Data to read from radio RX FIFO (60 bytes MAX.)
unsigned char rxData[4];
const int analogOutPin = 9;
int outVal=0;
void setup()
{
pinMode (analogOutPin,OUTPUT);
analogFrequency(20000);
Serial.begin(9600);
establishContact();
Radio.begin(0x01, CHANNEL_1, POWER_MAX);
Serial.print("Receiver");
}
void loop()
{
while (Radio.busy());
{
if (Radio.receiverOn(rxData, sizeof(rxData), 1000)>0 );
{
outVal=(100*(rxData[0]-0)+(10*(rxData[1]-0))+(rxData[2]-0));
// Serial.println((char*)rxData);
Serial.println(outVal);
analogWrite(analogOutPin,outVal);
}
}
}
void establishContact()
{
while (Serial.available() <= 0)
{
Serial.println("Rx Rx Rx"); // send an initial string
delay(300);
}
}