Ask a littleBits engineer

Hi,
Thanks for your prompt reply.
I used “Etch A Sketch - Processing”
I tried to change number as you said.
Finally I fixed it with No.4 ! Thanks Sean !!
d1/tx led is yellow solid, is that correct?

i’ve just received the little bits arduino module and was just stepping through the sample sketches first to get acquainted with it. a0 doesn’t seem to be responding as an input in for the 3 initial sketches i’ve tried. If I change these in the sketch to a1 and connect the button or analogue control to this (with the power behind it) it works. Is this a hardware issue?

is there any way to verify whether the board is working correctly or any other tips you have…

thanks dan

Hi Dan,

Usually when you cannot get a connection on a port it just has to be cleaned. Try taking a clean cloth and wiping the connector that you are having trouble with. If cleaning it doesn’t work and you are still having issues with that connector you may want to contact customer service to see if you can exchange it for a new module.

-Sean

Hi Sean,

Thanks for the reply. If I compare the pins of of a0 (and d0 which I also seem to be having issues with) to the a1 connection which is working, the middle pin’s are not sticking out from the plastic at all. I have tried cleaning them but am thinking this is the most likely cause?

Dan

Hi Dan!

I’m Allison, Bitizen Support Coordinator here at littleBits. I’m sending you a message through our emailing system to talk more about the troublemaking Arduino module. Don’t worry, we can replace it for you, if needed.

I just wanted to let you know to expect a note here shortly!

Best,
Allison

Hello Sean,

I’m trying to play two notes simultaneously with the Arduino module connected with two synth speaker modules (connected to d5 and d9 outputs). This code works for one speaker at the time

tone(5, 440, 1000);
delay(1000);
noTone(5);
tone(9, 440, 100);
delay(1000);
noTone(9);

But when I try to play at the same time only one speaker sounds

tone(5, 440, 1000);
tone(9, 440, 1000);
delay(1000);
noTone(5);
noTone(9);

It would be really helpful if you could explain why and/or if there is any solution to this problem.

Thanks.

1 Like

Hi Emil,

I believe the reason you are only hearing one tone when you use the tone function is that the tone function’s underlying source only allows for one tone at a time. The reason for this is that every frequency would require its own unique timer, but looking at the source code of the tone function reveals that it only uses a single timer, Timer 2.

I would recommend searching for some Arduino projects out there that drive multiple speakers. Here is a thread on the Arduino forum that looks like it covers such a project. Hopefully it will be a good starting point for you!

-Sean

Hi Sean,

I’m trying to do a follow up for issue #16357 that I have been emailing back and forth with Allison.
Would you be able to check the information I’ve sent her (along with the video and code) or do I have to send it all over again?
I also did everything she asked me and nothing works. I still get 5 LEDs regardless of my sketch.

Hi toomanyeduardus,

I’ll ask Allison for the video and code and get back to you with a response as soon as possible!

-Sean

Hi again Eduardo,

I see the sketch you are trying to load is:

void setup() 
{ 
pinMode(5, OUTPUT); 
}

void loop() 
{ 
analogWrite(5, 153); 
delay(1000);

analogWrite(5, 0); 
delay(1000); 
}

Can you try changing your code to the other pwm output pin to see if it works there?

void setup() 
{ 
pinMode(9, OUTPUT); 
}

void loop() 
{ 
analogWrite(9, 153); 
delay(1000);

analogWrite(9, 0); 
delay(1000); 
}

Also if you can, with the original code, can you tell me if there is any difference in behavior when you flip the switch from analog to pwm?

-Sean

Hi Sean,

well this is odd.
i tried my code without any modification first and the result was the same as before (all 5 LEDs blinking).
I changed the port to d9 and modified the code and only 3 LEDs turned on (which is good!)
Then I reverted to my previous code and changed the bargraph to port d5 as before, and it now works with the 3 LEDs…so it fixed itself?

I now have another question though, so please let me know if I should start a new thread for future references.
What’s the next step to have communication between the arduino and some other program? In other words, how can I make a C++ app that sends messages to this arduino sketch?
Can these sketches be compiled?
Basically now I want to write an external app that can modify the LEDs from 1 to 5, and I want the sketch to just run with the parameter sent, and determine the voltage on runtime.

Thanks!

Hi Eduardo,

I’m glad your Arduino is now working as expected! In regards to the external app, do you want to create a windows/mac program that you can control the Arduino with? There are a number of ways you can create such an application. There is a great page on the Arduino website that will introduce you to a number of methods of opening up communication between your Arduino and your computer. Hopefully that will be a good starting point for you!

-Sean

Hi, Sean. :slight_smile:
I am working on a musical project that requires the user to press a button into A0 in order to play the next song on d9 and turn on a fan bit for the duration of the song. It works correctly when a DC motor or an led is in d5, but when I try the circuit with a fan bit, the fan makes the circuit act as if I keep pressing the button. Do I need something like “debounce” code?
-Jude

Hi JackANDJude,

Can you post your code so I can look at it and see what might be going on with it? Thanks!

-Sean

int buttonPushCounter = 0;
const int Fan = 5;
int buttonPin = A0;
int speakerPin = 9;
#include “pitches.h”

// notes in the Jeopardy melody:
int jeopardy[] = {
NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F3, NOTE_C4, NOTE_F4, NOTE_C4,
NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4,
NOTE_A4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_CS4,
NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F3, NOTE_C4, NOTE_F4, NOTE_C4,
NOTE_F4, NOTE_D4, NOTE_C4, NOTE_AS3,
NOTE_A3, NOTE_G3, NOTE_F3};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int jeopardyDurations[] = {
4, 4, 4, 4, 4, 4, 2,
4, 4, 4, 4,
3, 8, 8, 8, 8, 8,
4, 4, 4, 4, 4, 4, 2,
3, 8, 4, 4,
4, 4, 4 };

// notes in the snow man melody:
int snowman[] = {
NOTE_DS4, NOTE_DS4, NOTE_DS4, NOTE_AS3, NOTE_DS4, NOTE_G4, NOTE_F4, NOTE_G4, 0, 0,
0, 0, NOTE_DS4, NOTE_DS4,NOTE_AS3, NOTE_DS4, NOTE_G4, NOTE_F4, 0, 0, 0, 0, 0,
NOTE_DS4, NOTE_DS4, NOTE_AS3, NOTE_DS4, NOTE_G4, NOTE_GS4, NOTE_G4, NOTE_DS4, 0, NOTE_C4, NOTE_GS4, NOTE_G4,
NOTE_DS4, 0, NOTE_DS4, NOTE_DS4, NOTE_AS3, NOTE_DS4, NOTE_G4, NOTE_B4, 0
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int snowmanDurations[] = {
8, 8, 8, 8, 8, 8, 4, 2, 4, 8,
4, 8, 8, 8, 8, 8, 8, 2, 4, 4, 8, 4, 8,
8, 8, 8, 8, 8, 8, 8, 4, 8, 8, 8, 8,
4, 8, 8, 8, 8, 8, 8, 4, 4
};

void setup ()
{
Serial.begin(9600);
pinMode (Fan, OUTPUT);
pinMode (buttonPin, INPUT);
pinMode (speakerPin, OUTPUT);
}

void loop ()
{ //int buttonreading = analogRead(A0)
if (analogRead(A0)!=0)
{
++buttonPushCounter;
analogWrite(Fan, 255);
if (buttonPushCounter == 1) { play_jeopardyMelody(); }
if (buttonPushCounter == 2) { play_snowmanMelody();
buttonPushCounter = 0; }
analogWrite(Fan, 0);

    }

};

void play_snowmanMelody(){
for (int thisNote = 0; thisNote < (sizeof(snowmanDurations)/2); thisNote++) {

// to calculate the note duration, take one second 
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int snowmanDuration = 1500/snowmanDurations[thisNote];
tone(speakerPin, snowman[thisNote], snowmanDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = snowmanDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speakerPin);

} }

void play_jeopardyMelody(){
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < (sizeof(jeopardyDurations)/2); thisNote++) {

// to calculate the note duration, take one second 
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int jeopardyDuration = 1000/jeopardyDurations[thisNote];
tone(speakerPin, jeopardy[thisNote], jeopardyDuration);

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = jeopardyDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(speakerPin);

}
}

Hey Sean,

I’ve got a question coming to you from our Community PRO RichB, Rich says,

“The Arduino Leonardo appears to have 28,672 bytes of memory for
programming. However, the littleBits Arduino at Heart module seems to have much
less. I would like to know how much memory is available for programming on
the littleBits Arduino at Heart module. Knowing this can help me (and
others) to avoid problems with the Arduino at Heart module.”

Hi JackANDJude,

Your problem is likely in this line

if (analogRead(A0)!=0)

You are doing an analog read on the pin which means if there is any amount of voltage detected on the line you will trigger the music. You need to change this to either be a digital read or change it to something like

if (analogRead(A0) > 50)

This way there is some allowance for small variations in voltage to the analog line.

-Sean

You rock! I had to go higher, and a jump to > 100 fixed it.

The Arduino Leonardo appears to have 28,672 bytes of memory for
programming. However, the littleBits Arduino at Heart module seems to have much
less. I would like to know how much memory is available for programming on
the littleBits Arduino at Heart module. Knowing this can help me (and
others) to avoid problems with the Arduino at Heart module.

Our Arduino module uses the same MCU as the Arduino Leonardo so the program memory available is the same as on the Arduino Leonardo which is 28,672 bytes

-Sean

Hey,
I am trying to do the LittleBits on Scratch project. I am having trouble with the paddle script. The video shows most of the script, but there is a number that begins with “4” and i’m not sure what it is.
I’m sorry if this is in the wrong forum…
Thanks,
Oshe10