Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    ilotek reacted to Fmilburn in MSP430G2553 with CC110L   
    That is a nice example, and as you said in your first post it does most of the work already. Here is a brief explanation of what is going on:
    Every Energia sketch has at least two functions: setup() and loop(). I'll concentrate on those two.
    setup() comes first and as the name implies it sets things up for the loop() that follows. It only executes once. In this section you will need to change the pinMode() and digitalWrite() functions for the new switch and LED as I outlined above.
    The loop() function that follows is the heart of the program and it loops endlessly over and over. In the following button check and transmission section checks to see if the button (switch) is pushed (on) and then sends a radio signal to the other radio.
    // Check for a button press. If the button is being pressed, load the txControl // into the radio TX FIFO and transmit it to the broadcast address. if (digitalRead(PUSH2) == LOW) { txControl.cmd = CMD_ON; } else { txControl.cmd = CMD_OFF; } Radio.transmit(ADDRESS_BROADCAST, (unsigned char*)&txControl, sizeof(txControl));All of this happens very quickly and only at the start of the loop. Nonetheless, the radio transmission must be allowed to complete which is what the following section does:while (Radio.busy());It waits until the radio is no longer busy transmitting and then moves on. All of the above happens very quickly. 
    In the receiver section it listens for up to one second (a very long time) for a signal from the other radio and responds appropriately with a digitalWrite() to make sure the LED is in the proper state.
    if (Radio.receiverOn((unsigned char*)&rxControl, sizeof(rxControl), 1000) > 0) { // Perform action based on incoming command: turn on/off red LED. if (rxControl.cmd == CMD_ON) { digitalWrite(RED_LED, HIGH); } else { digitalWrite(RED_LED, LOW); }The LED will stay on (or off) until it receives a new command to the contrary. 
    After this, the whole thing starts over again. A quick check to see if the button status has changed, a quick transmission, and then a 1 second wait if needed to see if the other radio is going to send something and updating if needed - over and over.
    So... I'm not sure you have to, but if you want to make one a pure transmitter and the other a pure receiver just remove the transmission and receiver sections respectively. To add LEDs and a switch you will need to change every instance of pinMode() and digitalWrite() as I outlined above.
    My suggestion - start with the LED. Then the switch. Then the transmission / receiver. If all of this is sounding like gibberish to you then I suggest studying some of the examples here: http://energia.nu/guide/
    Good luck, I'd be interested in how you get along.
    EDIT: I don't think you have to worry about pairing - it is taking care of this for you. Also, looks like I messed up the format of the code and hope that isn't confusing.
  2. Like
    ilotek got a reaction from Fmilburn in MSP430G2553 with CC110L   
    @@Fmilburn thank you for your help with this!  i think i've set it all up now.  i tested the code with an external switch, push button and LED to make sure that everything was working and we are good to go. here is the final (lol, last time i coded was in highschool, but i should know better than to never call a version final) code:
    transmitter module (rather than wait for a button push, i just set this thing up to always broadcast if it's turned on, so it has a power switch and the code runs automatically):
    #include <SPI.h> #include <AIR430BoostFCC.h> #define CMD_OFF 0 #define CMD_ON 1 struct sControl { unsigned char cmd; }; struct sControl txControl = { CMD_ON }; // TX control packet struct sControl rxControl = { CMD_OFF }; // RX control packet void setup() { Radio.begin(0x01, CHANNEL_1, POWER_MAX); } void loop() { Radio.transmit(ADDRESS_BROADCAST, (unsigned char*)&txControl, sizeof(txControl)); while (Radio.busy()); } and here is the receiving code:
    #include <SPI.h> #include <AIR430BoostFCC.h> #define CMD_OFF 0 #define CMD_ON 1 struct sControl { unsigned char cmd; }; unsigned char x = 0; struct sControl txControl = { CMD_OFF }; // TX control packet struct sControl rxControl = { CMD_OFF }; // RX control packet void setup() { Radio.begin(0x01, CHANNEL_1, POWER_MAX); pinMode(RED_LED, OUTPUT); digitalWrite(RED_LED, LOW); pinMode(P1_4, INPUT_PULLUP); } void repetition() { int x = 0; while (x < 100) { digitalWrite(RED_LED, HIGH); delay(100); digitalWrite(RED_LED, LOW); delay(100); x = x + 1; } } void loop() { if (Radio.receiverOn((unsigned char*)&rxControl, sizeof(rxControl), 1000) > 0) { if (rxControl.cmd == CMD_ON) { repetition(); digitalWrite(RED_LED, HIGH); } } if (digitalRead(P1_4) == LOW) { digitalWrite(RED_LED, LOW); } } the existence of P1_4 is just to detect a button press and turn the LED off.  because when repetition() is called the LED blinks for 20 seconds then stays on. 
    the only thing i have left for this project is to hook it up to battery power.  i'm thinking of using a 9V and then a voltage regulator to downstep it to 3.3V.
    i have a couple questions about wiring up LED's but i'll search around here for an answer before posting it here.
  • Create New...