Maker.io main logo

Hack Your Roshamglo Badge

2017-05-23 | By SparkFun Electronics

License: See Original Project

Courtesy of Sparkfun

Introduction

So you’ve put together your Roshamglo badge, and now you want more? Well, we can help you with that. In addition to playing infrared (IR) Rock-Paper-Scissors, the Roshamglo board can be reprogrammed with user-created code.

This will allow you to create your own applications for the badge. What can you make with some blinking lights, a five-way switch and IR communication? Well, how about a TV remote or a laser tag game, for starters.

Required Materials

The only things you’ll need to reprogram your Roshamglo badge are a fully constructed badge and a computer.

Suggested Reading

If you aren’t familiar with the following concepts, we recommend checking out these tutorials before continuing.

Hardware Overview

Note: This is a repeat section from the Roshamglo Hookup Guide, but it could be useful if this is the first place you've visited.

Hardware Overview

The Roshamglo uses the following:

      • ATtiny84
      • IR LED
      • IR receiver with built-in 38kHz demodulator
      • USB programming
      • Programmable red and green LED
      • Power switch
      • 5-way switch for input
      • Reset switch
      • 6 AAA PTH battery clips
      • 3 AAA batteries for power

The brains behind the Roshamglo is an ATtiny84, a lightweight Arduino-compatible microcontroller. The ATtiny84 comes with the following:

      • 8kB of flash memory for our program (~6kB after the bootloader is installed)
      • 512B of SRAM, which stores our variables used in our program
      • 512B of EEPROM
      • 12 I/O pins MAX (the Roshamglo breaks out 9 of these pins)
      • 10-bit analog-to-digital converter, which can be used on 8 pins

For details about what each pin is able to do, refer to the table below.

Roshamglo Pin Data Table

  Missing from the list are digital pins 9 and 10. The bootloader uses these two pins for USB programming.  

Roshamglo Pin Location

Each of these pins has been broken out to the edge of the board to make customization easy! If you would like to use any of these pins for something other than what it’s currently connected to, we provided jumpers that can easily be cut with a hobby knife. The only pins that do not have a jumper on them are the pins used for the five-way switch. The pins for the switch use the ATtiny’s internal pull-up resistors, so as long as the switch is not closed, the pin can be configured in any way you’d like without having to cut traces.

One Important Feature Missing

If you hadn’t noticed in the pin description, there was no mention of RX or TX pins. This is because, unfortunately, the ATtiny84 doesn’t have a hardware UART. The UART is used for serial communication, whether it’s for programming or printing messages to the serial window. You might be thinking, “But doesn’t the USB connector provide communication between the ATtiny and the computer?” You’re right; it does. To keep the bootloader size as small as possible, the bootloader only allows for USB programming. For serial debugging, you’ll need a USB cable and a USB-to-Serial adapter, and the SoftwareSerial library to send messages to a computer. You can learn more about serial communication here.

Install USB Driver

Roshamglo is emulating USB 1.1 using two of its pins. However, there are no common operating system drivers available that work with this custom USB class. As a result, we will need to install custom drivers in order to communicate with (and send our Arduino programs to) the Roshamglo board. Choose your operating system below and follow the directions to install the driver.

Note: We did not write the USB firmware nor the driver. We simply modified them to work with Roshamglo. The true geniuses are the fine folks who wrote micronucleus and libusb.

Windows

Make sure the Roshamglo board is OFF, hold the Down button (pull the five-way switch toward the SparkFun logo) and insert it into an available USB slot.

LED should begin to quickly flash red in short bursts

Once plugged in, the status LED should begin to quickly flash red in short bursts. This means the badge is in “Bootloader Mode.”

Quick Red Flashes means badge is in Bootloader Mode

Download the SparkFun ATtiny USB drivers by clicking on the link below.

Click to Download the SparkFun ATtiny USB drivers

Unzip the file. Open the Windows Device Manager, and you should see an Unknown device. Right-click on Unknown device and select Update Driver Software.

Select Update Driver Software

In the pop-up window, click Browse my computer for driver software.

Click Browse my computer for driver software

Click Browse… and open the folder that contains the drivers you just unzipped. It will likely be the sparkfun_attiny_usb_driver folder.

Click Browse > open the folder you just unzipped

Click Next. You may get a warning pop-up that says “Windows can’t verify the publisher of this driver software.” That’s OK. Just click Install the driver software anyway.

click Install the driver software anyway.

You should see a notification that the SparkFun ATtiny driver was installed successfully. Close that window, and verify that your Unknown device now shows up as SparkFun ATtiny in the Device Manager.

Device Manager

MacOS

You’ll need to install Homebrew and use it to install libusb. Enter the following commands into a Terminal:

Copy Code
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew install libusb-compat

Linux

Good news! Linux doesn’t require special drivers. However, you will need to do one of the following to be able to program Roshamglo from Arduino:

1) When you download the Arduino IDE (next section), make sure you run it as root: sudo ./arduino

download Arduino IDE, run it as root: sudo ./arduino

2) Or, you can add some udev rules so that Linux enumerates your device with write permissions. Create a file in rules.d:

Copy Code
sudo edit /etc/udev/rules.d/49-micronucleus.rules

Copy the following contents into that file:

Copy Code
# UDEV Rules for Micronucleus boards including the Digispark.
# This file must be placed at:
#
# /etc/udev/rules.d/49-micronucleus.rules (preferred location)
# or
# /lib/udev/rules.d/49-micronucleus.rules (req'd on some broken systems)
#
# After this file is copied, physically unplug and reconnect the board.
#
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666"
KERNEL=="ttyACM*", ATTRS{idVendor}=="16d0", ATTRS{idProduct}=="0753", MODE:="0666", ENV{ID_MM_DEVICE_IGNORE}="1"
#
# If you share your linux system with other users, or just don't like the
# idea of write permission for everybody, you can replace MODE:="0666" with
# OWNER:="yourusername" to create the device owned by you, or with
# GROUP:="somegroupname" and mange access using standard unix groups.

Save and exit.

Adding Arduino Compatibility

Arduino is not a full-featured development environment, but it does allow us to prototype embedded programs quickly and easily. To begin, navigate to Arduino’s software page and download the Arduino IDE for your operating system.

Click to Download Arduino IDE

If you need help installing Arduino for your operating system, you can follow this guide.

  Important! Your Roshamglo board will only work with Arduino versions 1.6.10 and above.  

Download and Install the Board Package

Because the Roshamglo board is not supported by the Arduino IDE by default, we need to add it manually. Open the Arduino program and go to File > Preferences. Then copy and paste the URL below into the Additional Board Manager URLs text box.

Copy Code
https://raw.githubusercontent.com/sparkfun/Arduino_Boards/tiny/IDE_Board_Manager/package_sparkfun_index.json

Need to add Arduino IDE manually

Then hit OK, and navigate to the Tools > Board > Boards Manager… tool. A search for “tiny” should turn up a SparkFun ATtiny Boards result. Select that and click Install.

navigate to the Tools > Board > Boards Manager

Once the installation is complete, go to Tools > Board and select Roshamglo (ATtiny84, 3.3V, 8MHz) under the SparkFun ATtiny Boards section.

Tools>Board & select Roshamglo (ATtiny84, 3.3V, 8MHz)

Make Something Blink

The Roshamglo board comes with two LEDs (a red LED and green LED built into one package), as well as a five-way switch (left, right, up, down and center). We can test that our Roshamglo board can be reprogrammed by writing and uploading a simple program.

Open the Arduino IDE and enter the following code:

Copy Code
void setup() {
pinMode(7, OUTPUT);
}

void loop() {
digitalWrite(7, HIGH);
delay(500);
digitalWrite(7, LOW);
delay(500);
}

Click on the Upload button.

Make Something Blink

If you are asked to save your work, click Cancel (save it if you want, but you don’t need to save to compile and upload your code).

Wait until you see Uploading appear in the Arduino IDE.

Make Something Blink

Make sure the Roshamglo board is OFF, hold the Down button (pull the five-way switch toward the SparkFun logo) and insert it into an available USB port while continuing to hold the Down button.

Make sure the Roshamglo board is OFF

Let go of the Down button, and the status LED should begin to quickly flash red in short bursts. This means the badge is in “Bootloader Mode.” You will need to do this every time you upload a new program to it.

Let go of the Down button

After a moment, you should see Done uploading appear in Arduino.

should see Done uploading appear in Arduino

Remove the Roshamglo board from your computer. Slide the power switch to ON.

Remove the Roshamglo board, Slide the switch to ON

And that’s it! Your Arduino should begin flashing the green LED on and off every second.

Arduino LED should flash green on & off every second

Note: If you get an error message while uploading, it could be caused by a variety of reasons. The way we're uploading programs to Roshamglo is actually hacked together, as we're emulating USB on the badge, which many computers do not like. Here are some things to try if you do get an error:

      • Try a different USB port
      • Unplug other USB devices
      • Close other programs that might be running
      • Reinstall the Roshamglo USB driver
      • Try a different computer

Resources and Going Further

Being able to make something blink is an important first step. You can now reprogram your Roshamglo to perform a wide variety of tasks, like blinking in different patterns, controlling the blink with the control stick, etc.

But wait, there’s more! The board comes equipped with an infrared (IR) transmitter and IR receiver. That means you could control TVs (with the right IR codes) or set up a simple “laser tag” game to play with your friends.

For more information, such as the Roshamglo source code, check out these resources:

 

 

Mfr Part # ATTINY84-20PU
IC MCU 8BIT 8KB FLASH 14DIP
Microchip Technology
More Info
View More Details
Mfr Part # 44012
KNIFE PRECISION WITH #11 BLADE
Aven Tools
Add all DigiKey Parts to Cart
Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.