Unknown problem with sketch

TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
Ok, I have my board working (finally!)

I uploaded the included blink code, and it worked perfectly.  So, now it's time to do my own first sketch.  Here's what I have:

Code: [Select]
//Pin Number Assignments:
const int LED1 = 4;

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

void loop()
  {
    digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(1000);              // wait for a second
    digitalWrite(LED1, LOW);  // turn the LED off by making the voltage LOW
    delay(1000);              // wait for a second
  }

I'm using the Tinycircuits proto terminal blocks tinyshield (ASD2005-R-T-I):


The LED, which is attached to ground and #4, comes on immediately; it then sort of blinks (as if you had an intermittent wire -- that's the effect) - and then is on, but dimly.  That's it.  There's no repetitive blinking.  I'm obviously missing SOMETHING, but I don't know what.  I'm an expert programmer in BASIC, C, C#, PHP, and am currently learning python.  The structure of the program is correct; I'm wondering if I have something connected wrong.

Also:  Do I have to "clear" the memory of the board before uploading new code, or does it simply overwrite the old?  Any help is appreciated.  Eventually, I'm going to have nine different LED's, blinking on various schedules.  What I'd like to have is this:

1. Blink on while #2 is off.
2. Blink on while #1 is off.
3. Blink on while #3 is off.
4. Blink on while #4 is off.
5. Random sequence with #5, #6, & #7.
6. Random sequence with #5, #6, & #7.
7. Random sequence with #5, #6, & #7.
8. Ramp up/down (different timing from #9)
9. Ramp up/down (different timing from #8)

Any help is greatly appreciated!


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
Glad to hear you were able to get the board programmed.

Is it possible that when inserting wires into the Proto Terminal Block TinyShield that you didn't tighten the screw enough? This would be the likely culprit for erratic LED behavior.

It is also possible to misread the pin labels on the board since the silkscreen font is tiny. Pin 4 is a corner pin. This is also different from pin A4. Is it possible the LED wired up is in the wrong terminal input?

Best,
RĂ©na
« Last Edit: March 18, 2021, 05:04:36 PM by lennevia »


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
Actually, I had the LED connected to #1, not #4; it turned on, then acted weird - probably because I was addressing the wrong pin.  Oops.  Can you tell me how do do a ramp up/ramp down (gradually brighter, gradually dimmer) for an LED?  Thanks!


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
You will need to use a PWM pin.

The Arduino IDE comes with a Fade Example built-in. I included a screenshot of how to navigate to the example using the File menu. The Arduino standard libraries, examples, and forums are all great places to learn about programming with Arduino. Since the TinyDuino uses the same processor, the programming part is all the same for the Arduino Uno.

Fade example tutorial: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade
Arduino forum: https://forum.arduino.cc/


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
Ok... but which pin is a PWM pin on this board??  I can't find anything online that tells me.



lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
On the TinyDuino Platform page, it lists: Pins IO3, IO5, IO6, IO9, SS (IO10), MOSI (IO11): These pins can provide an 8-bit PWM.

The page: https://tinycircuits.com/pages/tinyduino-overview

You can also use a traditional Arduino Uno pinout diagram, as seen here: https://content.arduino.cc/assets/Pinout-UNOrev3_latest.pdf (The PWM pins have the ~ symbol next to the pin numbers.)


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
You said that pins IO3, IO5, IO6, IO9, SS (IO10), MOSI (IO11) are PWM; I'm assuming you're referring to the pins marked 3, 5, 6, 9, SS  and MOSI; I have the LED connected to pin 9, but it does NOT do anything at all.

Code: [Select]
    int brightness = 0;    // how bright the LED is
    int fadeAmount = 5;    // how many points to fade the LED by
    // set the brightness of pin 6:
    analogWrite(LED06, brightness);
    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;
    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0 || brightness >= 255)
      {
        fadeAmount = -fadeAmount;
      }
    // wait for 30 milliseconds to see the dimming effect
    delay(30);

What am I missing here?  If I change the initial brightness to 255, the LED comes on, but never dims.  It's neither brightening nor dimming this LED.


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
You're not showing all of your program, so I can't be sure, but it looks like you are programming pin 6 instead of the pin 9 with your LED.

I recommend trying the Fade example by Arduino:

Code: [Select]
/*
  Fade

  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.

  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Fade
*/

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
Yes, I'm doing pin 6.  According to the site, 6 should be one of the PWM pins (3, 5, 6, 9, SS  and MOSI).  Am I reading this list wrong?  Or is IO6 = 6, and IO9 = 9?


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
You said that pins IO3, IO5, IO6, IO9, SS (IO10), MOSI (IO11) are PWM; I'm assuming you're referring to the pins marked 3, 5, 6, 9, SS  and MOSI; I have the LED connected to pin 9, but it does NOT do anything at all.

You typed pin 9 in your recent comment.

Is your LED facing the correct direction? I recommend trying the exact program and pin layout from the Arduino tutorial before making any edits or trying other pins so that you can make sure you are using a working program and working layout.


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
I tried both pin 9 and pin 6; neither did anything.  The red wire from the LED is going to the pin; the black wire to GND.  They light up normally with the digitalWrite(LED06, HIGH) command, so I know the LED's are both wired properly and working.


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
Send a picture of your hardware layout to verify the correct pin connections. I tested the example from Arduino and was able to get the fading behavior, picture attached of pin connections using jumper cables and pin 9.


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile


Yes, I know my wiring is a bit messy, but ALL of the LED's work independently, without lighting any adjacent ones.  I tried pins 3, 5, 6, and 9 - and none had any effect.


lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 437
    • View Profile
The messy wiring on the ground pin could be shorting the gnd to a voltage pin right next to it. What LED are you using?

Quote
ALL of the LED's work independently,

Are you saying all of your LEDs have been tested and work with the pins you are programming?

Quote
I tried pins 3, 5, 6, and 9 - and none had any effect.

Does this mean that you edited and uploaded the program for each pin as you changed your hardware configuration? Are you uploading to the correct TinyDuino pin? Do you get a "Done uploading." message each time you upload the program?


TheQuestor

  • Full Member
  • ***
    • Posts: 15
    • View Profile
I wrote a simple piece of code that illuminated each LED in turn, from 1 to 9.  They all worked.  I have LED's connected to pins 1-9.  I modified the dimming code to try pin 3, 5, 6, & 9 separately, and uploaded each.  Each uploaded successfully.


 

SMF spam blocked by CleanTalk