Reading and transmitting accelerometer values

Where did you put your if statement? Since rxPacket is defined inside a function, we call it a “local variable” and you can only refer to it inside that function. This is part of a broader concept called scope:

–David

Thank you! I forgot about that… :open_mouth:

I noticed a discrepancy between the accelerometer values received from the transmitting Wixel using the wireless_adc_rx program and the accelerometer values read directly from the transmitting Wixel connected to the computer.
This is the code to read accelerometer values in millivolts:

#include <wixel.h>
#include <time.h>
#include <usb.h>
#include <usb_com.h>
#include <adc.h>
#include <stdio.h>

uint32 lastToggle = 0;

void putchar(char c)
{
    usbComTxSendByte(c);
}


void updateprint()
{

    if (getMs() - lastToggle >= 1000)
    {
    	if (usbComTxAvailable() >= 64)
    	        {

    				adcSetMillivoltCalibration(adcReadVddMillivolts());

    	            printf("adc (mV): %d\r\n",  adcConvertToMillivolts(adcRead(0)));
    	        }
        lastToggle = getMs();
    }
}


void main()
{
    systemInit();
    usbInit();

    while(1)
    {
        boardService();
        updateprint();
        usbComService();
       usbShowStatusWithGreenLed();
        LED_RED(1);
    }
}

This program gives a peak voltage reading of about 2675 mV. Using the wireless_adc_rx program, the receiving Wixel displays a peak voltage reading of 1645 mV. Do you understand why they could be different?
Thanks!

You are probably getting a different reading because your program does not disable the internal pull-ups on the Wixel’s ADC inputs. On startup, all of the pins on the Wixel are configured to be inputs with pull-ups enabled (except for two pins that don’t have pull-ups or pull-downs). The wireless_adc_tx program disables the pull-ups on port 0 in its analogInputsInit() function if the input_mode parameter is 0 (the default). I think if you do this as well in your program, you will get readings that match the ones from wireless_adc_tx/rx.

- Kevin

Thank you, that worked!
One more question: I was wondering if you have advice for transmitting data back and forth between two Wixels. While one Wixel is executing the receiving function, the other Wixel needs to be executing the transmitting function. I’m not sure what the best way is to get them synchronized like this so they’re not both executing the same function. Can the transmitting Wixel get a confirmation that the receiving Wixel has received the data without it interfering with the program?

I think this statement has some assumptions in it which might not be necessary for your application. Instead of treating receiving and transmitting as two different modes, I recommend that you treat receiving and transmitting as two separate tasks that your program is constantly attending to. You could have a function in the main loop that receives data if there is any available in the buffers. You could have another function that sends data if it is time and there is space in the TX buffers. Both of these functions would be non-blocking and you would call them in your main loop. Whatever lower-level radio library you use will take care of switching the radio hardware between TX and RX as appropriate. Is there some reason this strategy wouldn’t work for you application?

Yes. If you use the radioLink (or radioCom) library, then you get confirmation (an ACK packet) whenever the other Wixel receives the packet, so the sending Wixel can know if the other Wixel got the message.

–David

I combined the receiving function in the wireless_adc_rx app and the transmitting function in the wireless_adc_tx app into a program for each Wixel, like this:

void main() {
    systemInit();
    usbInit();
    analogInputsInit();
    radioQueueInit();

    while(1)
    {
        boardService();
        updateLeds();
        usbComService();

        LED_YELLOW(0);
        radioToUsbService(); //receive accelerometer values
        adcToRadioService(); //transmit accelerometer values
    }

}

I only have one cable and regardless of which Wixel I connected to the computer to monitor in the terminal window, received data from the other Wixel was displayed. I don’t understand why the USB connection caused the hardware to switch to RX. You wrote:

How does the Wixel know whether to transmit or receive if there is both data available in the buffers and there is space in the TX buffers? For my application, I need Wixel #1 to transmit while Wixel #2 receives, until a condition is met and then they reverse with Wixel #1 receiving and Wixel #2 transmitting.

Thanks for your help!!

What you saw in the terminal window is the expected behavior, but the USB connection did not cause the radio to switch RX. The apps we are talking about use the radioQueue library. When there is nothing in the TX buffers, the radioQueue library puts the radio into RX mode so it can receive packets. You don’t have to explicitly tell the radioQueue library to receive packets; it does it automatically.

I think you might have gotten this question backwards and forgot to type “RX”. If there is space in the RX buffers, and data available to be transmitted in the TX buffers, then the radioQueue library will transmit the packets from the TX buffers, but between each packet it will let the radio sit in RX mode for approximately 1-4 ms. The randomness in the delay helps alleviate the risk that two Wixels will get into an identical state where each always transmits at the same time.

It’s good that you are curious about how things work, and you can look in the source code of the radioQueue library (only 234 lines) to learn more. However, all you really need to know about the radioQueue library is written on this Wixel SDK documentation page:
pololu.github.com/wixel-sdk/radio__queue_8h.html

The radioQueue library provides a queue for sending packets and a queue for receiving packets. You can then treat the two queues as two independent data pipes. The library takes care of switching the radio between RX and TX and all other lower-level details.

What exactly are you trying to do? What is this condition and how often is the condition met?

–David

Thanks for all the information! I’ll have to think about it…maybe a better way to phrase my question is if both Wixels have the same program running with the main function I posted, would you say that it’s “random” which Wixel is transmitting and which is receiving?
For my project, I have two servos on a robot that each cause the rotation of an accelerometer. I want to coordinate movements by having Wixel #1 transmit changing accelerometer values to Wixel #2, and when the received accelerometer value is beyond a threshold value, I want Wixel #2 to begin transmitting accelerometer values, and Wixel #1 to begin receiving the accelerometer values. So the “condition” is the accelerometer value and it would be met about every 10 seconds.

Yes.

I think you should just have each Wixel transmit its data regularly no matter what. Why do you need one of the Wixels to stop transmitting? Are you worried about filling up the available bandwidth with packets? How often do you want to send pulses to the servos (20 ms is standard)?

Alternatively, if you want more control over the timing of the packets and don’t mind making your programs a bit more complicated: You could designate one Wixel as the master and the other Wixel as the slave. The master would transmit its packets regularly. The slave would only transmit a packet right after receiving one from the master.

All of these ideas can be implemented with the radioQueue library.

–David

I need only one servo to be active until the received accelerometer value is above a threshold. The way I thought of implementing this would be to have a loop with the threshold condition within the receiving function that contains PWM code for the servo. That’s why I thought I would need that Wixel to stop transmitting because I would want it to remain in this loop in the receiving function.

I added code to the receiving function to conditionally run the servo based on the received value. I’m getting strange behavior from the Wixel when I include a while statement nested within an if statement. After downloading the program, the Wixel was suddenly not recognized by the computer and the LEDs weren’t on. I could only restore the USB connection and download a different program to it by manually putting the Wixel into bootloader mode. The while statements are commented out in the radioToUsbService() function. Do you know why this logic could cause this problem?

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>
#include <radio_queue.h>


/* VARIABLES ******************************************************************/
uint8 XDATA response[32];
PDATA volatile uint32 pwmCounter = 0; /* ticks of the pwm timer */
PDATA uint8 pwmPeriod = 200; /* how long the pwm wave lasts for: 20ms @ 10KHz */
PDATA volatile uint32 pwmPeriodNext = 200; /* when the next pwm period starts*/
PDATA volatile uint8 pwmPulse = 0; /* how long the pwm pulse last for: 1.5ms @ 10KHz */
PDATA volatile uint32 pwmPulseEnd = 15; /* when the pwm pulse ends */
int32 CODE param_input_mode = 0;
int32 CODE param_report_period_ms = 20;

/* FUNCTIONS ******************************************************************/
ISR(T3, 2) {
    pwmCounter++;
    if (pwmCounter == pwmPeriodNext)
    {
        if (pwmPulse)
        {
            setDigitalOutput(1, HIGH);
        }
        else
        {
            setDigitalOutput(1, LOW);
        }
        pwmPulseEnd = pwmCounter + pwmPulse;
        pwmPeriodNext += pwmPeriod;
    }
    else if (pwmCounter == pwmPulseEnd)
    {
        setDigitalOutput(1, LOW);
    }
}


void analogInputsInit()
{
	switch(param_input_mode)
	{
	case 1: // Enable pull-up resistors for all pins on Port 0.
	//This shouldn't be necessary because the pull-ups are enabled by default.
	P2INP &= ~(1<<5); //PDUP0 = 0: Pull-ups on Port 0.
	P0INP = 0;
	break;

	case -1: //Enable pull-down resistors for all pins on Port 0.
		P2INP |= (1<<5);
		P0INP = 0;
		break;

	default: //Disable pull-ups and pull-downs for all pins on Port 0.
		P0INP = 0x3F;
		break;

	}
}

void adcToRadioService()
{
	static uint16 lastTx = 0;

	uint8 XDATA * txPacket;

	//Check to see if it's time to send a report and if there's a radio TX buffer available.
	if ((uint16)(getMs()-lastTx) >= param_report_period_ms && (txPacket = radioQueueTxCurrentPacket()))
	{
		//Both of those conditions are true, so send a report.

		uint8 i;
		uint16 XDATA * ptr = (uint16 XDATA *)&txPacket[5];

		//This should be done before all the ADC readings, which take about 3 ms.
		lastTx = getMs();

		//Byte 0 is the length.
		txPacket[0] = 16;

		//Bytes 1-4 are the serial number.
		txPacket[1] = serialNumber[0];
		txPacket[2] = serialNumber[1];
		txPacket[3] = serialNumber[2];
		txPacket[4] = serialNumber[3];

		adcSetMillivoltCalibration(adcReadVddMillivolts());

		//Bytes 5-16 are the ADC readings on channels 0-6.
		for (i = 0; i < 6; i++)
		{
			*(ptr++) = adcConvertToMillivolts(adcRead(i));
		}

		radioQueueTxSendPacket();

	}
}



void updateLeds() {
    usbShowStatusWithGreenLed();
}


void softPwmInit() {
    T3CC0 = 75;
    T3IE = 1; // Enable Timer 3 interrupt.

    // DIV=101: 1:32 prescaler
    // START=1: Start the timer
    // OVFIM=1: Enable the overflow interrupt.
    // MODE=10: Modulo
    T3CTL = 0b10111010;
    EA = 1; // Globally enable interrupts.
}

typedef struct adcReport
{
	uint8 length;
	uint8 serialNumber[4];
	uint16 readings[6];
} adcReport;


void putchar(char c)
{
	usbComTxSendByte(c);
}

void radioToUsbService()
{
	adcReport XDATA * rxPacket;

	//Check if there is a radio packet to report and space in the USB TX buffers to report it.
if ((rxPacket = (adcReport XDATA *)radioQueueRxCurrentPacket()) && usbComTxAvailable() >= 64)
{
	//We received a packet from a Wixel

	printf(" %5u", rxPacket->readings[0]);
putchar('\r');
putchar('\n');

radioQueueRxDoneWithPacket();
}

if((rxPacket->readings[5]) < 1250){

//while((rxPacket->readings[5]) < 2015){

	pwmPulse = 16;
	if ((rxPacket = (adcReport XDATA *)radioQueueRxCurrentPacket()) && usbComTxAvailable() >= 64)
	{
		//We received a packet from a Wixel

		printf(" %5u", rxPacket->readings[0]);
	putchar('\r');
	putchar('\n');

	radioQueueRxDoneWithPacket();
	}

//}
	
	pwmPulse = 0;

}

else if((rxPacket->readings[5]) > 2015){

//while((rxPacket->readings[5]) > 1250){

	pwmPulse = 16;
	if ((rxPacket = (adcReport XDATA *)radioQueueRxCurrentPacket()) && usbComTxAvailable() >= 64)
	{
		//We received a packet from a Wixel

		printf(" %5u", rxPacket->readings[0]);
	putchar('\r');
	putchar('\n');

	radioQueueRxDoneWithPacket();

	}

							//}
	pwmPulse = 0;
	
								  }

else{
	pwmPulse = 0;
	return 0;
	}



}





void main() {
    systemInit();
    usbInit();
    softPwmInit();
    analogInputsInit();
    radioQueueInit();

    while(1)
    {

        boardService();
        updateLeds();
        usbComService();


        radioToUsbService(); //receive accelerometer values

        adcToRadioService(); //transmit accelerometer values
    }

}

you have to keep calling the “stayalive” routines inside tight loops else the radio doesn’t get serviced!
so inside your “while” loop include a call to

void stayAlive(void)
{
  boardService();
  updateLeds();
  usbComService();
  radioToUsbService()
}

Thank you for the suggestion…unfortunately I still get the same problem! This function call is inside the radioToUsbService() function, right? I’m confused about why the radioToUsbService() function is being called within the stayAlive function.

ah
didn’t realise it was inside the function already!

Thanks, that solved the hardware problem! :slight_smile:
Now my problem is that the logic in my program isn’t working because after I download the same program to both Wixels, their servos run continuously. Only one Wixel’s servo should be running as it’s receiving accelerometer values. I tried to debug by viewing the terminal window, but nothing is printed. Any suggestions? Thanks!

Hello, sheepcounter.

The indentation of your program makes it very hard to read. Eclipse has a “Correct Indentation” command in the Source menu you can use. Also I recommend configuring Eclipse to not use tab characters and use spaces instead.

In radioToUsbService, you are reading values from rxPacket even though rxPacket might be a null pointer (0). This will give you unexpected results because you will be reading from the wrong part of memory. When rxPacket is 0, it means that there is no packet to be processed.

–David

Ok I did the “Correct Indentation” command:

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>
#include <radio_queue.h>

/* VARIABLES ******************************************************************/
uint8 XDATA response[32];
PDATA volatile uint32 pwmCounter = 0; /* ticks of the pwm timer */
PDATA uint8 pwmPeriod = 200; /* how long the pwm wave lasts for: 20ms @ 10KHz */
PDATA volatile uint32 pwmPeriodNext = 200; /* when the next pwm period starts*/
PDATA volatile uint8 pwmPulse = 0; /* how long the pwm pulse last for: 1.5ms @ 10KHz */
PDATA volatile uint32 pwmPulseEnd = 15; /* when the pwm pulse ends */
int32 CODE param_input_mode = 0;
int32 CODE param_report_period_ms = 20;

/* FUNCTIONS ******************************************************************/ISR(T3, 2) {
	pwmCounter++;
	if (pwmCounter == pwmPeriodNext) {
		if (pwmPulse) {
			setDigitalOutput(1, HIGH);
		} else {
			setDigitalOutput(1, LOW);
		}
		pwmPulseEnd = pwmCounter + pwmPulse;
		pwmPeriodNext += pwmPeriod;
	} else if (pwmCounter == pwmPulseEnd) {
		setDigitalOutput(1, LOW);
	}
}

void analogInputsInit() {
	switch (param_input_mode) {
	case 1: // Enable pull-up resistors for all pins on Port 0.
		//This shouldn't be necessary because the pull-ups are enabled by default.
		P2INP &= ~(1 << 5); //PDUP0 = 0: Pull-ups on Port 0.
		P0INP = 0;
		break;

	case -1: //Enable pull-down resistors for all pins on Port 0.
		P2INP |= (1 << 5);
		P0INP = 0;
		break;

	default: //Disable pull-ups and pull-downs for all pins on Port 0.
		P0INP = 0x3F;
		break;

	}
}

void adcToRadioService() {
	static uint16 lastTx = 0;

	uint8 XDATA * txPacket;

	//Check to see if it's time to send a report and if there's a radio TX buffer available.
	if ((uint16) (getMs() - lastTx) >= param_report_period_ms && (txPacket
			= radioQueueTxCurrentPacket())) {
		//Both of those conditions are true, so send a report.

		uint8 i;
		uint16 XDATA * ptr = (uint16 XDATA *) &txPacket[5];

		//This should be done before all the ADC readings, which take about 3 ms.
		lastTx = getMs();

		//Byte 0 is the length.
		txPacket[0] = 16;

		//Bytes 1-4 are the serial number.
		txPacket[1] = serialNumber[0];
		txPacket[2] = serialNumber[1];
		txPacket[3] = serialNumber[2];
		txPacket[4] = serialNumber[3];

		adcSetMillivoltCalibration(adcReadVddMillivolts());

		//Bytes 5-16 are the ADC readings on channels 0-6.
		for (i = 0; i < 6; i++) {
			*(ptr++) = adcConvertToMillivolts(adcRead(i));
		}

		radioQueueTxSendPacket();

	}
}

void stayAlive() {

	boardService();
	updateLeds();
	usbComService();

}

void updateLeds() {
	usbShowStatusWithGreenLed();
}

void softPwmInit() {
	T3CC0 = 75;
	T3IE = 1; // Enable Timer 3 interrupt.

	// DIV=101: 1:32 prescaler
	// START=1: Start the timer
	// OVFIM=1: Enable the overflow interrupt.
	// MODE=10: Modulo
	T3CTL = 0b10111010;
	EA = 1; // Globally enable interrupts.
}

typedef struct adcReport {
	uint8 length;
	uint8 serialNumber[4];
	uint16 readings[6];
} adcReport;

void putchar(char c) {
	usbComTxSendByte(c);
}

void radioToUsbService() {
	adcReport XDATA * rxPacket;

	//Check if there is a radio packet to report and space in the USB TX buffers to report it.
	if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
			&& usbComTxAvailable() >= 64) {
		//We received a packet from a Wixel

		printf(" %5u", rxPacket->readings[0]);
		putchar('\r');
		putchar('\n');

		radioQueueRxDoneWithPacket();
	}

	if ((rxPacket->readings[5]) < 1250) {

		while ((rxPacket->readings[5]) < 2015) {

			stayAlive();
			pwmPulse = 16;
			if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
					&& usbComTxAvailable() >= 64) {
				//We received a packet from a Wixel

				printf(" %5u", rxPacket->readings[0]);
				putchar('\r');
				putchar('\n');

				radioQueueRxDoneWithPacket();
			}

		}

		pwmPulse = 0;

	}

	else if ((rxPacket->readings[5]) > 2015) {

		while ((rxPacket->readings[5]) > 1250) {

			stayAlive();
			pwmPulse = 16;
			if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
					&& usbComTxAvailable() >= 64) {
				//We received a packet from a Wixel

				printf(" %5u", rxPacket->readings[0]);
				putchar('\r');
				putchar('\n');

				radioQueueRxDoneWithPacket();

			}

		}
		pwmPulse = 0;

	}

	else {
		pwmPulse = 0;

	}

}

void main() {
	systemInit();
	usbInit();
	softPwmInit();
	analogInputsInit();
	radioQueueInit();

	while (1) {

		boardService();
		updateLeds();
		usbComService();

		radioToUsbService(); //receive accelerometer values

		adcToRadioService(); //transmit accelerometer values
	}

}

In radioToUsbService, I thought I was following the same format of code in the wireless_adc_rx app. Doesn’t the if ((rxPacket = (adcReport XDATA *)radioQueueRxCurrentPacket()) && usbComTxAvailable() >= 64) statement check to see if there’s a packet to report?

Yes, it does, but the code you wrote to read rxPacket is outside the if statement so it will run regardless of whether rxPacket is null or not. That’s just how if statements work:

void foo()
{
  if (x)
  {
    ... // This code runs if x is true (non-zero)
  }

  ... // This code always runs assuming there is nothing special above to alter the flow (like a return statement)
}

–David

Thanks, I didn’t realize it was outside of the if statement. I’m still having trouble with my program because the back and forth communication and running the servo conditionally in the receiving function isn’t working. I was wondering if this method makes any sense:

#include <wixel.h>
#include <usb.h>
#include <usb_com.h>
#include <stdio.h>
#include <radio_queue.h>

/* VARIABLES ******************************************************************/
uint8 XDATA response[32];
PDATA volatile uint32 pwmCounter = 0; /* ticks of the pwm timer */
PDATA uint8 pwmPeriod = 200; /* how long the pwm wave lasts for: 20ms @ 10KHz */
PDATA volatile uint32 pwmPeriodNext = 200; /* when the next pwm period starts*/
PDATA volatile uint8 pwmPulse = 0; /* how long the pwm pulse last for: 1.5ms @ 10KHz */
PDATA volatile uint32 pwmPulseEnd = 15; /* when the pwm pulse ends */
int32 CODE param_input_mode = 0;
int32 CODE param_report_period_ms = 20;

/* FUNCTIONS ******************************************************************/ISR(T3, 2) {
	pwmCounter++;
	if (pwmCounter == pwmPeriodNext) {
		if (pwmPulse) {
			setDigitalOutput(1, HIGH);
		} else {
			setDigitalOutput(1, LOW);
		}
		pwmPulseEnd = pwmCounter + pwmPulse;
		pwmPeriodNext += pwmPeriod;
	} else if (pwmCounter == pwmPulseEnd) {
		setDigitalOutput(1, LOW);
	}
}

void analogInputsInit() {
	switch (param_input_mode) {
	case 1: // Enable pull-up resistors for all pins on Port 0.
		//This shouldn't be necessary because the pull-ups are enabled by default.
		P2INP &= ~(1 << 5); //PDUP0 = 0: Pull-ups on Port 0.
		P0INP = 0;
		break;

	case -1: //Enable pull-down resistors for all pins on Port 0.
		P2INP |= (1 << 5);
		P0INP = 0;
		break;

	default: //Disable pull-ups and pull-downs for all pins on Port 0.
		P0INP = 0x3F;
		break;

	}
}

void adcToRadioService() {
	static uint16 lastTx = 0;

	uint8 XDATA * txPacket;

	//Check to see if it's time to send a report and if there's a radio TX buffer available.
	if ((uint16) (getMs() - lastTx) >= param_report_period_ms && (txPacket
			= radioQueueTxCurrentPacket())) {
		//Both of those conditions are true, so send a report.

		uint8 i;
		uint16 XDATA * ptr = (uint16 XDATA *) &txPacket[5];

		//This should be done before all the ADC readings, which take about 3 ms.
		lastTx = getMs();

		//Byte 0 is the length.
		txPacket[0] = 16;

		//Bytes 1-4 are the serial number.
		txPacket[1] = serialNumber[0];
		txPacket[2] = serialNumber[1];
		txPacket[3] = serialNumber[2];
		txPacket[4] = serialNumber[3];

		adcSetMillivoltCalibration(adcReadVddMillivolts());

		//Bytes 5-16 are the ADC readings on channels 0-6.
		for (i = 0; i < 6; i++) {
			*(ptr++) = adcConvertToMillivolts(adcRead(i));
		}

		radioQueueTxSendPacket();

	}
}

void stayAlive() {

	boardService();
	updateLeds();
	usbComService();

}

void updateLeds() {
	usbShowStatusWithGreenLed();
}

void softPwmInit() {
	T3CC0 = 75;
	T3IE = 1; // Enable Timer 3 interrupt.

	// DIV=101: 1:32 prescaler
	// START=1: Start the timer
	// OVFIM=1: Enable the overflow interrupt.
	// MODE=10: Modulo
	T3CTL = 0b10111010;
	EA = 1; // Globally enable interrupts.
}

typedef struct adcReport {
	uint8 length;
	uint8 serialNumber[4];
	uint16 readings[6];
} adcReport;

void putchar(char c) {
	usbComTxSendByte(c);
}

void radioToUsbService() {
	adcReport XDATA * rxPacket;

	//Check if there is a radio packet to report and space in the USB TX buffers to report it.
	if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
			&& usbComTxAvailable() >= 64) {
		//We received a packet from a Wixel

		printf(" %5u", rxPacket->readings[5]);
		putchar('\r');
		putchar('\n');

		radioQueueRxDoneWithPacket();
	}
	if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
			&& usbComTxAvailable() >= 64) {
		if ((rxPacket->readings[5]) < 1250) {

			while ((rxPacket->readings[5]) < 2015) {

				stayAlive();
				pwmPulse = 16;
				if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
						&& usbComTxAvailable() >= 64) {
					//We received a packet from a Wixel

					printf(" %5u", rxPacket->readings[5]);
					putchar('\r');
					putchar('\n');

					radioQueueRxDoneWithPacket();
				}

			}

			pwmPulse = 0;

		}

		else if ((rxPacket->readings[5]) > 2015) {

			while ((rxPacket->readings[5]) > 1250) {

				stayAlive();
				pwmPulse = 16;
				if ((rxPacket = (adcReport XDATA *) radioQueueRxCurrentPacket())
						&& usbComTxAvailable() >= 64) {
					//We received a packet from a Wixel

					printf(" %5u", rxPacket->readings[5]);
					putchar('\r');
					putchar('\n');

					radioQueueRxDoneWithPacket();

				}

			}
			pwmPulse = 0;

		}

		else {
			pwmPulse = 0;
		}
	}
}

void main() {
	systemInit();
	usbInit();
	softPwmInit();
	analogInputsInit();
	radioQueueInit();

	while (1) {

		boardService();
		updateLeds();
		usbComService();

		radioToUsbService(); //receive accelerometer values

		adcToRadioService(); //transmit accelerometer values
	}

}