I had an issue using digital pins 0 and 1 on an Arduino Uno (read here) This was solved by using other pins as those one are used for serial com (king of conflict)
I now have another situation where i use pins 10 for a seven segments display and 13 for a push button. It doesn't work as expected (neither the display or the button work at all).
After some investigation, i have notices the pin 10 is also the SS communication pin and 13 is also SCK pin so this leads me to try on other "simple" I/O pins and guess what, this works great !
So i was wondering if pins 10 and 13 are prone to conflicts and why ? (i have read on a thread that pin 10 tend to disable interrupts, which i am actually using on pins 2 and 3 to update the display)
Is so, is it possible to force those pins to act as simple I/O pins (like disable SPI or something) ? or do i have to use other pins ?
yeah sure i can use other pins, but i was too confident and everything is now soldered...
So if any possibility to fix the issue via software that would be perfect !
And i would be glad to have your intel about what is going on...
galloro:
After some investigation, i have notices the pin 10 is also the SS communication pin and 13 is also SCK pin so this leads me to try on other "simple" I/O pins and guess what, this works great !
So i was wondering if pins 10 and 13 are prone to conflicts and why ? (i have read on a thread that pin 10 tend to disable interrupts, which i am actually using on pins 2 and 3 to update the display)
Is so, is it possible to force those pins to act as simple I/O pins (like disable SPI or something) ? or do i have to use other pins ?
The SCK and SS pins can be used as I/O but only if you do not use the SPI library.
If you don't use the SPI library , then they are OK as I/O.
Tom...
Yeah i did breadboard, but checked every parts one by one (display, then rotary, then push button), not everything at once. And everything worked seperately.
So the segment module is the Velleman VMA425
and here is the code :
#include <TM1637Display.h>
#define ROTARY_CLK 2
#define ROTARY_DT 3
#define ROTARY_SW 4
#define DISPLAY_CLK 9
#define DISPLAY_DIO 10
#define BUTTON_PIN 7
#define LED_PIN 8
int buttonState = 0; // variable for reading the pushbutton status
int timerSec = 0;
int timerMin = 0;
int timerSetMode = 1; // toggle set of min or sec. Default = seconds
int rot_clkValue = LOW;
int rot_dtValue;
int rot_lastState = LOW;
int rot_swState;
unsigned long lastRotarySwPress = 0; // tempo 50ms to avoid click errors
unsigned long lastRotClk = 0; // tempo 50ms to avoid rotation errors
TM1637Display lcd = TM1637Display(DISPLAY_CLK, DISPLAY_DIO);
//int allON[] = { 0xff, 0xff, 0xff, 0xff };
//int allOFF[] = { 0x00, 0x00, 0x00, 0x00 };
void setup() {
pinMode(ROTARY_CLK, INPUT);
pinMode(ROTARY_DT, INPUT);
pinMode(ROTARY_SW, INPUT_PULLUP);
pinMode(DISPLAY_CLK, INPUT);
pinMode(DISPLAY_DIO, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN,LOW);
pinMode(BUTTON_PIN, INPUT);
lcd.setBrightness(1);
lcd.clear();
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(ROTARY_CLK), onRotaryClkChange, CHANGE);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(BUTTON_PIN);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(LED_PIN, HIGH);
} else {
// turn LED off:
digitalWrite(LED_PIN, LOW);
}
// Read the Rotary button state
int rot_swState = digitalRead(ROTARY_SW);
//If we detect LOW signal, button is pressed
if (rot_swState == LOW) {
//if 50ms have passed since last LOW pulse, it means that the
//button has been pressed, released and pressed again
if (abs(millis()) - lastRotarySwPress > 50) {
timerSetMode *=-1;
}
// Remember last button press event
lastRotarySwPress = millis();
}
}
void onRotaryClkChange() {
String msg; // DEBUG !!
rot_clkValue = digitalRead(ROTARY_CLK);
if (rot_lastState == LOW && rot_clkValue == HIGH) {
rot_dtValue = digitalRead(ROTARY_DT);
if (rot_dtValue == LOW) {
if (timerSetMode == 1) {
timerSec++;
msg = "\nOrientation : Positif / Mode : Sec / timerSec : " + String(timerSec);
Serial.println(msg);
}
else {
timerMin++;
msg = "\nOrientation : Positif / Mode : Min / timerMin : " + String(timerMin);
Serial.println(msg);
}
}
else {
if (timerSetMode == -1) {
timerSec--;
msg = "\nOrientation : Negatif / Mode : Sec / timerSec : " + String(timerSec);
Serial.println(msg);
}
else {
timerMin--;
msg = "\nOrientation : Negatif / Mode : Min / timerMin : " + String(timerMin);
Serial.println(msg);
}
}
lcd.showNumberDecEx(timerSec, 0b01000000, false, 2, 2);
lcd.showNumberDecEx(timerMin, 0b01000000, false, 2, 0);
}
rot_lastState = rot_clkValue;
}
The Arduino - and particularly your TM1637 - require 5 V to operate. You need to have a 5 V supply, such as a switchmode "buck" regulator from your 12 V.
The TM1637 uses an idiosyncratic protocol which vaguely resembles I2C but is not a "bus" protocol and cannot be shared.
Why are you using "String"s?
Why are you using interrupts?
Why are you attempting to use Serial.println() in an interrupt routine?
I am using an external power supply to power a 12V led strip and a 12V fan triggered by the Arduino.
Paul__B:
The Arduino - and particularly your TM1637 - require 5 V to operate. You need to have a 5 V supply, such as a switchmode "buck" regulator from your 12 V.
Yep ! I use the external power to power the Arduino using Vin (which is supposed to be for that purpose ? which accepts from 5V to 12V right ?) which then distributes 5V to the other devices.
Paul__B:
The TM1637 uses an idiosyncratic protocol which vaguely resembles I2C but is not a "bus" protocol and cannot be shared.
I am lost I am just using a library there so...
And what do you mean by "cannot be shared" ?
Paul__B:
Why are you using "String"s?
Just using it to print debug text to serial console
Paul__B:
Why are you using interrupts?
To read CLK and DT channels from a rotary encoder
Paul__B:
Why are you attempting to use Serial.println() in an interrupt routine?
Debug ? ok maybe this is not a thing that should be done that way...
Let me know if i am doing anything wrong (obviously i do !). Here to learn
galloro:
Yep ! I use the external power to power the Arduino using Vin (which is supposed to be for that purpose?
Sort of. You can power the Arduino itself using Vin. What you cannot do, particularly using 12 V, is to use the severely limited current capability of the on-board regulator without a heatsink, to power external devices or draw significant currents from multiple output pins.
galloro:
which accepts from 5V to 12V right?)
No. Minimum 7 V and running from 12 V is maximally stressing the heat dissipation of the regulator which may result in occasional shutdown (crash).
galloro:
which then distributes 5V to the other devices.
As long as they do not draw significant current.
galloro:
And what do you mean by "cannot be shared" ?
You cannot connect more than one display to the same two pins, unlike using I2C,
galloro:
To read CLK and DT channels from a rotary encoder
Unless you are spinning the rotary encoder rapidly - in which case you do have problems - it is easier and more reliable to poll the encoder in a properly written loop(). Unfortunately generating serial output (expecting to send out more than one character at a time) is going to foul up everything.
Paul__B:
Sort of. You can power the Arduino itself using Vin. What you cannot do, particularly using 12 V, is to use the severely limited current capability of the on-board regulator without a heatsink, to power external devices or draw significant currents from multiple output pins.
Minimum 7 V and running from 12 V is maximally stressing the heat dissipation of the regulator which may result in occasional shutdown (crash). As long as they do not draw significant current.
Yes i am aware of this limitation. I am just powering le led display and the rotary encoder. The other devices are powered from 12V AC supporting 8 Amps
Paul__B:
You cannot connect more than one display to the same two pins, unlike using I2C,
Ok. Just using one 4 digits module requiring only 2 pins
Paul__B:
Unless you are spinning the rotary encoder rapidly - in which case you do have problems - it is easier and more reliable to poll the encoder in a properly written loop(). Unfortunately generating serial output (expecting to send out more than one character at a time) is going to foul up everything.
Good to know ! will fix this !
So you think this my problems could be an electrical issue ?
galloro:
So you think this my problems could be an electrical issue ?
Certainly possible.
In fact, likely. Your suggestion that powering the Arduino from 12 V via "Vin" causes failure would indeed support that. If 12 V DC is readily to hand, then a proper switchmode "buck" regulator feeding the "5V" pin would be the logical approach. Alternatively, a common USB "phone charger" plugged into the USB port would be able to supply anything up to 500 mA and is perfectly fine as a permanent solution.
You say the 5 V is only powering the display and rotary encoder but I wonder how much the display actually draws and under what circumstances? Care to cite (which is to say, Web link) what display it is?
That's the strict rule of the forum - unless you cite with Web links what you actually mean by each thing such as a "TM1637 display" we can only guess what the thing is and it may be something quite different and behave quite differently to what we would assume.
i have found that when i remove the button pull down resistance (R6 on my schematic) LED Strip lights up and and Fan is spinning... And then i put R6 back everything works as expected...
Well, according to the datasheet, if you were to display "8888", it would draw a solid 140 mA or so which would certainly overload the on-board regulator. Lesser numbers of segments would clearly draw proportionate currents. So the display could be a cause of shutdown.
At least that module - unlike the vastly cheaper ones on eBay - has (according to the schematic at least) the correct capacitors on the data lines.
TomGeorge:
Can you post pictures of your project please so we can see your component layout?
OK ! i'll have to consider adding a 5V regulator then...
On the other side, i came across some similar projects on the net that relies on a similar layout so i was confident...
Ok for the pics ! i didn't imagine this was useful as it can be difficult to sort out, even i am scratching my head sometimes