Getting started with your #PiWars badge

So, if you were at Pi Wars this weekend you may have been lucky enough to pick up the awesome Pi Wars 2019 badge made by Gareth over at 4Tronix

This brilliantly cool little device is actually an Arduino micro controller, a 5×5 LED matrix, 4 push buttons and a light sensor all in one package. The code that currently runs the badge is available on GitHub HERE

But, if you’ve never used an Arduino before it can be a little confusing what to do if you want to start playing around with it.

So, here’s a quick guide to setting up what you need, and then changing the display to show your name.

You’ll need….

A PiWars 2019 Badge (No, really!)

A data capable USB – microUSB cable (Make sure it’s one that provides data transfer and not just power)

A laptop / PC (The following is for Windows based machines – for Mac / Linux the configuration of USB-serial will be different but everything else remains the same)

First, plug the badge into your laptop or PC using the USB cable. The badge will power up and run the program that’s already installed on it, scrolling ‘Pi Wars 2019’ on the display.

On your PC, you’ll see ‘Installing device…’ message displayed

Now wait. And wait.

You should eventually see ‘USB COM x successfully installed’. This means USB port is now correctly configured as a serial port and the Arduino software will be able to see it. Make a note of this number – you’ll need it soon!

Next, download the Arduino IDE here and install it.

When you run the Arduino IDE, it’ll show the following screen:

Screen Shot 2019-04-03 at 20.54.26

This is a blank ‘sketch’ which is the name for an Arduino program. Programs are written in a language called ‘Processing’ and if you’re used to your Raspberry Pi and using Python or Scratch it’s a bit different. It’s a ‘compiled’ language which means that the (almost!) human readable code you see is translated into the actual bits and bytes that the microcontroller (the Arduino) can understand. This compiled code is then uploaded to the Arduino and once that’s done you can turn it on and off and the program will still be stored and will run whenever you turn it on.

So – to start making changes, firstly we need to make sure that the Arduino IDE can see your badge correctly and is ready to program it.

Under the Tools menu, scroll down to ‘Ports’ and make sure this is set to the same COM port that was created when you plugged the badge in. (It will usually be COM4 or COM5)

Next, again in Tools menu, scroll down to Boards, and then select Arduino / Genuino UNO.

Lastly, back to Tools menu, scroll down to Programmer and select ArdunioISP

Your IDE and badge are now set up and ready to be re-programmed!

(Thanks to Gareth at 4Tronix for confirming these settings!)

Next, download the badge program from GitHub HERE

Then, in the Arduino IDE click File – Open and open the badge.ino file you just downloaded.

You should now see the following displayed:

Screen Shot 2019-04-03 at 21.53.54

This is the sketch that’s already been compiled and uploaded to the badge. If you scroll approximately 1/3 of the way down you will see where the ‘User code and defines’ section starts which looks like this:

// —————————————-
// User variables and defines
byte mode; // Defines the display mode: Static, Scrolling characters, animation, dynamic
int cycle=0; // Variable to count rate of scrolling
#define CYCLERATE 300
#define SCROLLRATE 100
#define ANIRATE 100
#define PIXELS 1
#define NUM_LEDS 14
#define BRIGHT 80
String text1 = “0123456789”;
String text2 = ” PiWars 2019 “;
int charIDX=0;
int offset=0; // offset from start of character. Used in scrolling

int L1 = A3, L2 = 10; // Left Motor Drive pins
int R1 = 11, R2 = A4; // Right Motor Drive pins
int mCount=0;
int mState=0;

// —————————————-

‘String text2’ is the variable which stores the scrolling text that is currently displayed when the badge is turned on.

Change this to your name – or anything you like!

Next, go to the Sketch menu – and click Verify / Compile.

You may well then get the following error! (If not – skip this section)

Screen Shot 2019-04-03 at 19.47.19

This error means a library needed to run the LEDs is not installed. Fortunately this is easy to fix. Go to the Sketch menu > Include Library > Manage Libraries.

Search for FastLED in the search box which should then show the following screen:

Screen Shot 2019-04-03 at 19.48.33

Install the FastLED by Daniel Garcia library which should be the top result. Now if you compile the sketch again it should compile successfully.

Finally, in the Sketch menu click on upload and your updated program will now be compiled and uploaded to your badge. The badge will turn off briefly and when it turns on again your new text will now be scrolling brightly for you!

There is LOADS more that can be done with this little board, if you search through the code, you’ll see where the buttons are defined and how these can be used to do lots of different things – there’s also the light sensor on the eye that also adds another dimension….

But we’ll save that for another post :)

Until next time….


Read More