Page 1 of 1

Unable to get serial to work

Posted: Thu Nov 29, 2012 11:37 pm
by AlchemyCS
Hi Everyone,

My first post here, so apologies if this is too much or too little info!

I've recently purchased a leostick but I'm having trouble getting the serial port(s) to work from a sketch. Probably something simple I've overlooked, but some help would be appreciated.

* The leostick has v1.1 on the board and I use the "Freetronics LeoStick V1.0" profile to program through the arduino programmer.
* I am able to upload various sketches to blink the various on-board LEDs
* I can only upload a new sketch by resetting the stick and uploading during the 7s bootloader run
* I'm using a MacBook Pro with OS X 10.7.5
* Following this post viewtopic.php?f=29&t=753 I found setting the board to Leonardo failed to upload the sketch.
* I tried replacing the

Code: Select all

while (!Serial) { ; }

Code: Select all

* Using the below sample code I can see the led blinking ok, but no serial data.
* Serial data lights don't blink when expected
* I've tried using both

Code: Select all


Code: Select all

with no luck

This is the baseline test sketch I am using. Each time I tweak the sketch I can verify it is the new one running by changing the LED that blinks:

Code: Select all

  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 10;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  Serial.println("Hello World");
Any help or suggestion would be greatly appreciated!

Re: Unable to get serial to work

Posted: Sun Dec 02, 2012 1:47 am
by AlchemyCS
Hi Everyone,

I've had progress on this and have found some interesting interactions with the more recent mac models. Note that my topic was about the serial communications from a sketch, but this issue also includes the Keyboard and Mouse HID.

I tested the sample sketch from my initial post on a Linux box (Ubuntu) and it had no problems. I have discovered the following compatibility matrix with Macs I have current access to:

Mac Mini, 10.8.2, Mid 2011 - FAIL
iMac, 10.8.2, Mid 2007 - OK
Mac Book Pro, 10.7.4, Mid 2009 - OK
Mac Book Pro, 10.7.4, Early 2011 - FAIL
Mac Mini, 10.6.8 (server), Early 2009 - OK

So this looks like it works no problems on older macs but has issues on newer macs.

I have also found that when plugging the leostick into the 'OK' macs for the first time the keyboard detection dialog appears, but this is not the case for the 'FAIL' macs. I tried deleting the /Library/Preferences/ and rebooting but this had no effect.

Here is where it get's interesting...

As a bit of fun I programmed into the leostick the 'tunes' sketch posted on viewtopic.php?f=29&t=162. Note this was done on a 'FAIL' computer (my computer with all my dev software). Once the leostick rebooted and started playing a tone the keyboard dialog appeared!

I reprogrammed the stick with my original test sketch but serial, keyboard and mouse still failed. I then tried plugging the same stick into the same 'FAIL' computer via a USB hub and this worked! I tried this on all the other 'FAIL' computers with the same results.

So to get the Serial, Mouse and Keyboard to be detected on the newer macs you need to play a tone or plug it in via a USB hub.

Now I haven't run any measurements, but intuitively it feels as though the newer macs are expecting a certain current draw to be notified that the device exists as a serial, keyboard or mouse device. But then again, why does the leostick loader work? Puzzled.

Anyway I am happy to have found a temporary resolution and can get on with what I was hoping to do.

Has anyone had any similar findings? Any thoughts?

Re: Unable to get serial to work

Posted: Sun Dec 02, 2012 3:59 am
by cef
First thing I would be doing is trying to put a delay (eg: 1 second) at the start of your sketch and seeing if this helps.

It could be that things are firing off too fast and the newer Mac's don't start USB fast enough to see the data.

Might not work, but IMO that would be about the only "tangible' result of playing the tone.

Re: Unable to get serial to work

Posted: Wed Dec 05, 2012 12:19 am
by AlchemyCS
Hi cef,

Thanks for your input. I doubted it is was simply a delay issue as it would mean that any uploaded sketch should trigger the HID detection at some point, but this wasn't the case. HID detection only occurs after the first tone is generated.

To be thorough I did try your suggestion with delays ranging from 1s to 8s at 1 second intervals all with no luck.

However I appear to have a solution by forking and updating the supplied Freetronics core. I've created a new board type 'LeoStick V1.1' with a modified core and using this causes the HID detection to work as expected. I have a few more tests to run (once the wife has released me from active xmas decoration duty). Once I'm happy with the tests I will post the code.

Re: Unable to get serial to work

Posted: Wed Dec 05, 2012 4:45 am
by effgee
AlchemyCS wrote:(once the wife has released me from active xmas decoration duty)
What ?! There's xmas decorations that don't rely on an arduino ? I won't have a word of it.
You need to educate your wife as to what is a real xmas decoration.

Re: Unable to get serial to work

Posted: Mon Dec 10, 2012 1:59 am
by AlchemyCS
effgee wrote: What ?! There's xmas decorations that don't rely on an arduino ? I won't have a word of it.
You need to educate your wife as to what is a real xmas decoration.
I know, I know....I was going to show her your post but she was in the kitchen with a cleaver so I thought better of it...

Re: Unable to get serial to work

Posted: Mon Dec 10, 2012 2:15 am
by AlchemyCS
Ok, so after all my fluffing around trying to get the core to work as expected on modern mac computers the final refactoring is elegantly simple: don't use the Freetronics core, use the one that comes with the ardiuno IDE 1.0 (I'm using and tested with 1.0.2).

To do this you just have to make a slight modification to the boards.txt file in the arduino ide. The contents that need to be added to the file are available at gist 4222258.

This allows the LeoStick HID and serial to be detected by newer macs without issue. Interestingly it also allows the use of the tone() api without locking the board. It will show up in the IDE as Freetronics LeoStick V1.2 and Freetronics LeoStick V2.2

I've only tested this in mac and linux, so the magical windows *.inf file might need to be changed for windows.

If you have installed the ArduinoIDE 1.0.2 on a mac in the standard location (under /Applications) then you can easily amend your board.txt file with this one liner from the terminal:

Code: Select all

curl >> /Applications/ 
Perhaps this would be worth posting on the LeoStick install and first time use - Mac OS X thread which has only the initial post back in February this year?

Re: Unable to get serial to work

Posted: Sat Jan 05, 2013 3:26 am
by argon
Thank you AlchemyCS

After quite a bit of frustration, your fix helped me get my first LeoStick project going.