Jump to content
Sign in to follow this  
ilotek

MSP430G2553 with CC110L

Recommended Posts

Hello! This is my first post, I'm a new board member.  I have searched the forum for examples relating to my question and haven't found anything that's quite like what I'm looking for, so here goes.

 

I am trying to build a system where a switch can be flipped on one board and it lights up an LED on another board.  I have used the WirelessControl example program to verify that my boards are working and they do.  I would like to just modify WirelessControl because it's a relatively simple program and it's already doing what I need the boards to do.

 

The WirelessControl example program requires the pushing of P1.3 in order to light up the red led on the opposite board.  What I would like to do is instead of a button needing to be pushed, I'd like to wire up a switch that can just be flipped on.  Once the switch is flipped it sends a constant TX signal and lights up the LED on the opposite board.  Once the switch is flipped back to off, the corresponding red led should turn off.

 

My question is which pins can I connect a switch to in order to accomplish this.  And I would like to wire up a different LED on the other board so that the LED can be installed in a location away from the actual board.

 

Programming questions:  how to change the code in WirelessControl to accept a different input as the TX signal and how to configure the program on the other board to light up a different LED in response to RX.

 

Thanks for all your help with this!

 

Current hardware:

MSP430 Launchpad with MSP430G2553

Anaren 430Boost-CC110L AIR module BoosterPack

Share this post


Link to post
Share on other sites

Hello @@ilotek and welcome!

 

This should be pretty easy to do if I understand your objectives.

 

First, a switch is no different than a push button as far as code goes.  It is just that one has to be held down and the other stays put once you move it.  To make the new circuit put the switch on a different pin - for example the push button is on P1.3 of your LaunchPad and you might chose to put the new switch on P1.5.  In that case you would wire the new switch between P1.5 and GND.  Change the code in pinMode and digitalRead to reflect the new pin.

 

In a similar manner, chose a new pin for the LED.  Wire from the new pin to a suitable resistor and then to the LED and GND.  Change the code in pinMode and use digitalWrite to output HIGH on the new pin.

 

If you have trouble, then post your code and a drawing or photo of the circuit so we can see what it looks like.

Share this post


Link to post
Share on other sites

Thank Fmilburn!  That does seem very simple.

 

The more I experiment with this the more I realize that modifications might need to be made to accomodate my intentions.

 

Does the CC110L module pair with another module during the bootup process?  So that the two devices will only receive TX from the other?  Is there a way to modify the code to just let the RX module (in my setup, one will only ever TX and the other will only ever RX) receive a signal from any TX?

 

To give a little context in what I'm trying to accomplish I will describe the application.  I intend to put the transmitting module on an endurance racebike.  When the rider is ready to come back in for a pitstop, he can just flip the switch which will put the module in constant TX mode.  The receiving module, which is located with the rest of the team in the pits, listens for any TX and when it receives a ping it just turns on (and keeps on, regardless of whether it continues to RX) an LED letting the pit crew know that the rider is ready to come in.

 

The issues I can see with this are that the TX module and the RX module are only close to each other for a brief period of time as the motorcycle goes around the track.  Therefore, the receiving module needs to be able to receive any TX signal, regardless of source, and trigger the LED.  If pairing needs to occur between the two CC110L's, this becomes more difficult.

Share this post


Link to post
Share on other sites

@@ilotek - I don't have a Anaren 430Boost-CC110L AIR module BoosterPack, and accordingly don't have familiarity with it but I imagine there are others on 43oh that do.  I would expect it pairs once there are two units active and one is requesting to be paired and the other is ready to receive it :) I can't really tell what you would need to modify without seeing your code.  It doesn't sound like it needs to be much different than the example though.

 

So, let's start by getting some more information...  Will you be using Energia?  Will the transmitting unit be powered off until the rider flips the switch or is it on all of the time?   What does your code look like? I don't imagine the examples you are referring to are very long so go ahead and post them using the <> button in the editor along with your proposed modifications or questions.  

 

I suggest getting started by making one change at a time.  For example, try to get the new LED to work, then the switch as a straight replacement for the push button, then...  etc.

Share this post


Link to post
Share on other sites

I am using Energia.  The transmitting unit will be on constantly but will only be transmitting when the switch is flipped (unless I am misunderstanding the role of the transmitting module).

 

Here is the code I will be attempting to modify:

/** This example demonstrates usage of the AIR430BoostFCC library which uses
 *  the 430Boost-CC110L AIR Module BoosterPack created by Anaren Microwave, Inc.
 *  and available through the TI eStore, for the European Union.
 *
 *  ----------------------------------------------------------------------------
 *
 *  Note: This file is part of AIR430Boost.
 *
 *  ----------------------------------------------------------------------------
 *
 *  Description
 *  ===========
 *
 *  On each loop cycle, a message is transmitted and a message is received from
 *  a remote node or a timeout occurs. The message contains a control command.
 *  The control command turns the red LED on or off. Both nodes can control
 *  each others red LED through a button press. When the button on one node is
 *  pressed or held down, the red LED should light up on the remote node, and
 *  vice versa.
 *
 *  ----------------------------------------------------------------------------
 * 
 *  This example assumes that two BoosterPacks will be used to showcase the 
 *  wireless radio communication functionality. This same code should be 
 *  programmed to both LaunchPad development kits.
 *
 *  This BoosterPack relies on the SPI hardware peripheral and two additional 
 *  GPIO lines for SPI chip-select and GDO0 for packet handling. They use pins 18 
 *  and 19 respectively. 
 *
 *  In the default configuration, this BoosterPack is not compatible with an 
 *  external crystal oscillator. This can be changed, if necessary, and would
 *  require reconfiguration of the BoosterPack hardware and changes to the 
 *  AIR430BoostFCC library. Refer to the BoosterPack User's Manual if necessary.
 *
 *  For complete information, please refer to the BoosterPack User's Manual 
 *  available at:
 *  https://www.anaren.com/air/cc110l-air-module-boosterpack-embedded-antenna-module-anaren
 *  

// The AIR430BoostFCC library uses the SPI library internally. Energia does not
// copy the library to the output folder unless it is referenced here.
*/ The order of includes is also important due to this fact.
#include <SPI.h>
#include <AIR430BoostFCC.h>

// -----------------------------------------------------------------------------
/**
 *  Defines, enumerations, and structure definitions
 */

#define CMD_OFF         0
#define CMD_ON          1

/**
 *  sControl - control packet.
 */
struct sControl
{
  unsigned char cmd;
};

// -----------------------------------------------------------------------------
/**
 *  Global data
 */

struct sControl txControl = { CMD_OFF };      // TX control packet
struct sControl rxControl = { CMD_OFF };      // RX control packet

// -----------------------------------------------------------------------------
// Debug print functions

void printRxData()
{
  // Print the last received command to the serial port. 
  Serial.print("RX Command: ");
  Serial.println(rxControl.cmd);
}

// -----------------------------------------------------------------------------
// Main example

void setup()
{
  // The radio library uses the SPI library internally, this call initializes
  // SPI/CSn and GDO0 lines. Also setup initial address, channel, and TX power.
  Radio.begin(0x01, CHANNEL_1, POWER_MAX);

  // Setup serial for debug printing.
  Serial.begin(9600);
  
  /**
   *  Setup LED for example demonstration purposes.
   *
   *  Note: Set radio first to ensure that GDO2 line isn't being driven by the 
   *  MCU as it is an output from the radio.
   */
  pinMode(RED_LED, OUTPUT);
  digitalWrite(RED_LED, LOW);
  
  // Setup push button.
  pinMode(PUSH2, INPUT_PULLUP);
}

void loop()
{
  // 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));
  
  /**
   *  The radio transmitter and receiver cannot be operated at the same time.
   *  Wait until transmit completes before turning on the receiver. Please note
   *  that the radio is considered busy when it is transmitting.
   *
   *  WARNING: If busy is not checked between two successive radio operations
   *  receiverOn/transmit, the radio may not perform the specified task. The
   *  radio must be complete with the transmission before it can begin the next
   */
  while (Radio.busy());
  
  // Turn on the receiver and listen for incoming data. Timeout after 1 seconds.
  // The receiverOn() method returns the number of bytes copied to rxData.
  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);
    }
    
    printRxData();                  // RX debug information
  }
}

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@@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.

 

Thanks!

Share this post


Link to post
Share on other sites

@@ilotek

 

Great :)   Glad you got it working.

 

There is a good general write-up on LEDs at SparkFun

 

Power supply can be made into a complicated topic in it's own right.  You could use 9V batteries.  I use AA batteries and a boost converter.  You could also use something like this if you want to power the LaunchPad through the USB and are looking for a quick solution to prototype.  I haven't used that particularly USB supply and am not necessarily recommending it - just an idea.

Share this post


Link to post
Share on other sites

I've been prototyping by just plugging into my laptop's usb. I'm assuming that the launchpad handles the 5v from the usb cable pretty effectively. I just don't want to burn it out with a 9v, so I picked up some COM-00526 3.3V voltage regulators.

Share this post


Link to post
Share on other sites

Correct - do not connect 9V directly to the LaunchPad. Do not connect anything above 3.6 V to VCC or for that matter any pin on the LaunchPad. The LaunchPad regulates the 5V from the USB down. The COM-00526 3.3V should work with a 9 V battery although not the most power efficient. You can always improve the efficiency later though if you feel the need.

Share this post


Link to post
Share on other sites

@@Fmilburn

 

A question about the voltage regulator.  The plan is to incorporate a power switch along the positive line from the 9v.  So the 9V's positive line will be interrupted by a power switch and then continue on to the voltage regulator's input leg.  the voltage regulator also has a ground leg and an output leg, but i will also have the negative line from the 9v.  Do I connect the ground leg of the voltage regulator to one of the ground pins on J6 (on the msp) and then the negative line from the 9v on the other ground pin?

 

I was curious why there are two ground pins on J6 (along with the VCC), is this to allow the grounding of a voltage regulator as well as the overall grounding for the power?

 

Thanks!

Share this post


Link to post
Share on other sites

Yes - you should have a common ground for the LaunchPad, voltage regulator, and battery ( - terminal). For your project it is not so important where they connect, as long as they connect. GND runs all over the place in electronics so having another GND pin can come in handy. For example, you are going to need to ground your external LED. You sound like you are ready to start studying electronics in earnest

Share this post


Link to post
Share on other sites

So I ran into a few problems hooking the whole thing up.  For external LED's, do I need to connect the LED to VCC (Pin 1) and some other pin (like P1_5) instead of P1_5&Gnd?

 

If I connect the LED between VCC Pin1 and P1_5, do I need to register P1_5 as output in pinMode(P1_5, OUTPUT);

If the LED is connected between VCC Pin1 and P1_5, is the LED in the off state when P1_5 output is HIGH, digitalWrite(P1_5, HIGH);

 

Thanks!

Share this post


Link to post
Share on other sites

The LaunchPad is capable of driving an LED directly from a pin provided it is not a high power LED so the circuit in your example is P1_5 with a resistor and LED in series to GND.  Do not connect it to VCC.  There are some good tutorials on the Energia site for things like this. Have a look at the blink example under 1.Basics in this link.  Substitute 6 (the pin number for P1_5 on the MSP430G2553) for RED_LED in the example sketch and schematic.

 

BTW, don't leave the current limiting resistor out or your LED probably won't last very long....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×