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 Hats Off Fascinator 9: Connections Part Deux
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: brenyc13
  • Date Created: 13 Sep 2014 3:36 PM Date Created
  • Views 591 views
  • Likes 0 likes
  • Comments 1 comment
  • serial_debugging
  • jaunty_fascinator
  • hats_off
  • adafruit_gemma
  • adafruit
Related
Recommended

Hats Off Fascinator 9: Connections Part Deux

brenyc13
brenyc13
13 Sep 2014

A short video where I talk about serial debugging.


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


In my last post I talked generally about connecting the Gemma and the Flora Accelerometer. Here, I tried to put that into action.


Thank You, Becky Stern

A few weeks ago, Adafruit Wearables Pro Becky Stern posted this tutorial for serial debugging with the Gemma. I decided to try it out. But then I missed the bit about leaving off the “receive” cable and had to spend some time figuring out how to connect the accelerometer’s data line to the Gemma.


Assistance

I also had to call in a favor with my Hunky Assistant to get his help working with the software serial and figuring out how to get the code to do what I wanted it to do. In the video I mention connecting the hardware and then working with the code to get it to work but I was really working with both of them on and off at the same time.


// GEMMA serial debugging with Flora Accelerometer


#include <SoftwareSerial.h>
#include <TinyWireM.h>


#define ACCEL_ADDR (0x32 >> 1)
#define OUT_X_L_A 0x28
#define CTRL_REG1_A 0x20
#define OTHER_REG_COMING_UP 0x80




// Establish software serial on digital pin 1
SoftwareSerial mySerial = SoftwareSerial(0, 1);


int sensorValue;       // Current


void init_accelerometer()
{
  TinyWireM.beginTransmission(ACCEL_ADDR);
  TinyWireM.send(CTRL_REG1_A);
  TinyWireM.send(0x37);
  TinyWireM.endTransmission();
}


void setup() {
  mySerial.begin(9600);

  TinyWireM.begin();

  init_accelerometer();
}


int16_t recv_2bytes()
{
  uint16_t v;

  uint8_t l = TinyWireM.receive();
  uint8_t h = TinyWireM.receive();

  v = h;
  v <<= 8;
  v |= l;


  return v;
}


void get_accelerometer_values(int16_t *x, int16_t *y, int16_t *z)
{
  TinyWireM.beginTransmission(ACCEL_ADDR);
  TinyWireM.send(OUT_X_L_A | 0x80);
  TinyWireM.endTransmission();

  TinyWireM.requestFrom(ACCEL_ADDR, 6);

  *x = recv_2bytes();
  *y = recv_2bytes();
  *z = recv_2bytes();
}


void loop() {
  delay(500);
  int16_t x,y,z;
  get_accelerometer_values(&x, &y, &z);

  mySerial.println(x);
  mySerial.println(y);
  mySerial.println(z);
  mySerial.println("");
}


Importance of Snacks

My big takeaway from this part of the process is to eat while working. I started getting listless on the home stretch due to some low blood sugar. My thought processes weren’t as snappy. Won’t make this mistake again.

image

 

It Worked!

In the end, we were able to read the three axis values created by the accelerometer. I'll whip up another post just about trying to come up with an algorithm to produce the LED behaviors this should trigger.

  • Sign in to reply
  • DAB
    DAB over 10 years ago

    Good Post.

     

    You are right about always keeping snacks and a drink handy when debugging.

    Time will pass quickly when you are focused deeply on a project.

     

    It is always good to step back recheck your connections.  It is also good to have someone else to talk to while you debug.  Just explaining things to someone, even if they do not know what you are saying will usually jog your memory enough to set you straight.

     

    Keep going, you are doing good.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
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