Tags:
create new tag
, view all tags
This enables the checksum function of the packet code, set this to 0x00 to deactive the checksum function or 0x80 to use checksums

Using the Command Library

As mentioned in "Controlling the eBug via the Multiplexer", Nick D'Ademo has written a command library which will generate command packets for us, without too much fuss. Still, while these commands are fairly straight forward, I'll break down exactly how to use them and what to use them for so as to save time for future students. For the library itself, click here

There are 18 commands in total:

  1. StepperMotorLeftStep(int16_t freqHz, int16_t nSteps, bool directionForward, int8_t stepMode, bool rgbON, bool xBee, int8_t options)
  2. StepperMotorRightStep(int16_t freqHz, int16_t nSteps, bool directionForward, int8_t stepMode, bool rgbON, bool xBee, int8_t options)
  3. StepperMotorLeftRightStep(int16_t freqHz1, int16_t nSteps1, bool directionForward1, int8_t stepMode1, bool rgbON1, int16_t freqHz2, int16_t nSteps2, bool directionForward2, int8_t stepMode2, bool rgbON2, bool xBee, int8_t options)
  4. StepperMotorStopBoth(bool disable1, bool disable2, bool xBee, int8_t options)
  5. StepperMotorStopLeft(bool disable, bool xBee, int8_t options)
  6. StepperMotorStopRight(bool disable, bool xBee, int8_t options)
  7. TLC5947_SetAllRed(int16_t value, bool xBee, int8_t options)
  8. TLC5947_SetAllGreen(int16_t value, bool xBee, int8_t options)
  9. TLC5947_SetAllBlue(int16_t value, bool xBee, int8_t options)
  10. TLC5947_SetAll(int16_t value, bool xBee, int8_t options)
  11. TLC5947_SetAllOff(bool xBee, int8_t options)
  12. TLC5947_SetRed(int8_t led, int16_t value, bool xBee, int8_t options)
  13. TLC5947_SetGreen(int8_t led, int16_t value, bool xBee, int8_t options)
  14. TLC5947_SetBlue(int8_t led, int16_t value, bool xBee, int8_t options)
  15. TLC5947_SetMultiple(int16_t mask1, int16_t mask2, int16_t mask3, int16_t value, bool xBee, int8_t options)
  16. TLC5947_SetMultipleHold(int16_t mask1, int16_t mask2, int16_t mask3, int16_t value, int16_t mask, bool xBee, int8_t options)
  17. TLC5947_SetAllHold(int16_t value, int16_t mask, bool xBee, int8_t options)
  18. LM35_GetTemperature(bool xBee, uint8_t options)
Each command has its own variables which need values when calling the command. I think the easiest way to explain this in terms of how to use the commands would be break the commands up into two seperate categories, then discuss how each variable acts in relation to the function itself. Most of the functions are fairly self-explaitory in what they actually do, but if there are any which I deem to be slightly ambiguous, I'll endevor to outline their roles as clearly as possible.

Anyway, lets break our functions into two seperate categories:

  • Motor Control
  • LED Control

Motor Control

Name of Variable Range of Variable What it does
freqHz 0x0000-0x0200 This variable is tied in with two others, "nSteps" and "stepMode". Freq referes to the amount of steps per second the wheel will rotate. So a large this makes the wheel rotate faster while slowing it will require a small value to be used here. I find a comfortable value to set this to is 0x00FF.
nSteps 0x0000-0x0200 As the name would suggest, this is the number of steps the wheel will complete for the duration of this command. There are roughly 251 steps to a single wheel revolution. To set the motor to run continuesly, set this value to 0
directionForward true, false This values whether the wheel rotates anti-clockwise, (forwards using the true value), or clockwise, (reverse using the false value)
stepMode 0x00-0x08 Adjusts the freq value, so 0x00=full speed, 0x01= half speed, 0x02= 1/4 speed, 0x03= 1/8 speed, 0x08= 1/16 speed
rgbON true, flase This one is fairly obvious, switches on LED's when true and executing commands. Looks pretty but if using the LED's to track position make sure you leave it off
xBee true, false This identifies which device the packet is being sent via. Setting this to true says that the packet is being sent via the xBee chip, (so wirelessly). If it is false, it says that the packet is being sent via the uart.
options 0x00-0x80 This enables the checksum function of the packet code, set this to 0x00 to deactive the checksum function or 0x80 to use checksums
disable true, false This variable only pops up in the motor disable functions, making this true will disable whichever motor is being referenced in the particular function, while leaving it as false leaves it to run as normal

LED Control

Name Of Variable Range of Variable What it does
value 0-4095 This adjusts the LED intensity, so 0=lowest and 4095 is brightest
xBee true, false This identifies which device the packet is being sent via. Setting this to true says that the packet is being sent via the xBee chip, (so wirelessly). If it is false, it says that the packet is being sent via the uart.
options 0x00-0x80 This enables the checksum function of the packet code, set this to 0x00 to deactive the checksum function or 0x80 to use checksums
led 0x01-0x0F This enables the checksum function of the packet code, set this to 0x00 to deactive the checksum function or 0x80 to use checksums
mask 0x00-0xFF See below

The mask variable pops in a couple of functions, and is a bit tricky to use, so lets examine how to use it in these functions individually

TLC5947_SetMultiple(uint16_t mask1, uint16_t mask2, uint16_t mask3, uint16_t value, bool xBee, uint8_t options)


This command can be used for setting multiple LED's to whatever colour you want. There are a couple of tricks which one should keep in mind when it comes to controlling this command. Firstly, even though they're listed seperately, I find it easier for understanding how this command works if you treat "mask1", "mask2", and "mask3" as one 48 bit int. The other thing is that the thing that controls each LED is not the number, well it is the number, but don't think of it in terms of values, but rather which bits are high to give a certain value. It is the bits which control the LED's, and I find it much easier to understand if you think of it in terms of bits rather than values.

So each 3 bits controls one LED, with the bottom 3 bits corresponding to LED one and ascending from there. So like this:

LED LED16 LED16 LED16 LED15 LED15 LED15 LED14 LED14 LED14 LED13 LED13 LED13 LED12 LED12 LED12 LED11 LED11 LED11 LED10 LED10 LED10 LED9 LED9 LED9 LED8 LED8 LED8 LED7 LED7 LED7 LED6 LED6 LED6 LED5 LED5 LED5 LED4 LED4 LED4 LED3 LED3 LED3 LED2 LED2 LED2 LED1 LED1 LED1
Bit 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Mask Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 3 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 2 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1 Mask 1


Converting can be a pain, so heres a handy binary to Hex converter: http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html

So within our 3 bit LED values, there is a range from 0-7. Each individual value set a different color on the LED, which are as follows:
0 = LED 0ff
1 = Red
2 = Green
3 = Yellow
4 = Blue
5 = Purple
6 = Teal
7 = White

TLC5947_SetMultipleHold(uint16_t mask1, uint16_t mask2, uint16_t mask3, uint16_t value, uint16_t mask, bool xBee, uint8_t options)


This function works like the "TLC5947_SetMultiple" command, except with an extra element introduced. The variable mask is a 16 bit integer. Each bit here corresponds to an LED and when this bit is high, it will hold whichever value it is already displaying regradless on the input. Other than that the commands behave exactly like "TLC5947_SetMultiple", so:

mask1,mask2,mask3 = 48 bit LED color control

mask = LED Hold control

-- AlYoung - 2013-02-05

Topic revision: r3 - 2013-02-19 - AlYoung
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback