element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Hats Off Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Hats Off Design Challenge
  • More
  • Cancel
Hats Off Design Challenge
Blog Sherlock Holmes Case Hat - 2: Debugging Values on the Gemma using an LED
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 8 Sep 2014 5:43 AM Date Created
  • Views 269 views
  • Likes 0 likes
  • Comments 0 comments
  • hats_off
  • case_hat
Related
Recommended

Sherlock Holmes Case Hat - 2: Debugging Values on the Gemma using an LED

Former Member
Former Member
8 Sep 2014

Today, I was going to do a video and post on how to use the HCSR04 Ultransonic Rangefinder, but I may have accidentally set it down on some energized wires and fried it. That's alright though, I have a box of them over at my local hackerspace, Makers Local 256, so I should be able to get that video up soon.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Instead, I'm going to talk about debugging on the Gemma, since it works a little bit differently than other Arduino-based microcontrollers. The Gemma board does not have a built-in serial-to-USB converter so you cannot send or receive data using the Arduino serial console or other console applications. If you have your own serial-to-usb cable or adapter, and have two IO pins on your Gemma to spare, you can use a software serial library to add data transfer capabilities by following Becky Stern's wonderful Gemma serial debugging tutorial on Adafruit. If you have a sensor that needs two IO pins or don't have access to a serial-to-usb converter, there are still some tricks you can use to provide a little bit of data feedback.

 

The idea I'm using to read back some simple values is to blink an LED a number of times equal to the value. So if my ultrasonic rangefinder sees an object three feet away, it will blink three times. If you're looking to check values higher than ten or so, you can divide the value by a number to keep the number of blinks from being too high. The code that I reference here and in the video is available on my GitHub repo for the Case Hat project here.

 

First define the pin we're going to use for the LED. The Gemma has a built-in LED on IO Pin 1, so we'll use that:

const int LED_PIN = 1;

 

Then in the setup() function, we need to delay by a couple of seconds because the Gemma LED fades in and out on boot, to show that the Gemma is ready to receive code. Since we want to count the number of blinks, this fading in and out can cause some confusion, so let's let that settle down first for 3000 ms (or 3 seconds).

void setup() {

  delay(3000);

 

Set the LED pin as an output:

  pinMode(LED_PIN, OUTPUT);

 

Blink three times for the value '3', and then pause for a bit (I'll explain how this function works later):

  blinkDebug(3);

  delay(2000);

 

Blink three times for the value '2', and then pause for a bit:

  blinkDebug(2.4);

  delay(2000);

 

Blink three times for the value '3', and then pause for a bit:

  blinkDebug(2.6);

  delay(2000);

}

 

Nothing is going on the main loop:

void loop() {

}

 

The blinkDebug() function takes in a floating-point number and blinks that many times rounded to the nearest integer:

void blinkDebug(double debugValue){

 

Rounding to an integer is not as simple as converting the floating point, because that just truncates (or cuts off) the digits after the decimal place. So to make sure it rounds to the nearest number rather than just round down, we add 0.5 to the value before converting it to an integer. So a number like 2.6 turns to 3.1 and then is truncated to 3, but 2.4 turns to 2.9 and truncates to 2. There are certain types of numbers that this doesn't work on through, what sort of numbers would cause a problem with this scheme?

  int roundedValue = (debugValue+.5);


Loop the number of times we calculated, and blink the light on for a little while and then off.

  for (int i=0; i<roundedValue; ++i) {

    digitalWrite(LED_PIN, HIGH);

    delay(200);

    digitalWrite(LED_PIN, LOW);

    delay(200);

  }

}

 

So this is just a quick little method I've used to get some values out of the Gemma due to its lack of serial port. If you need larger values you can divide the number before blinking, or multiple the value if you are trying to display small values less than one. Full source can be found at https://github.com/tylercrumpton/Gemma-Case-Hat/blob/master/LedDebugging/LedDebugging.ino

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube