11
votes
How can I stop digital pins from floating at reboot?
You could in principle set the pin state a little bit earlier, by
plugging your code into the C runtime's initialization sequence. This,
however, will only buy you a few microseconds: the pins will ...
6
votes
How can I set up outputs without using digitalWrite?
digitalWrite() is just a convenience function to hide away complexity from the user, so that she/he can just use a pin number and a value. This complexity takes some time to execute. If this is too ...
5
votes
Accepted
What is the equivilent of PORTx for Teensy (4.0)?
All Teensies support digitalWriteFast out of the box. digitalWriteFast compiles to just setting the bit in the right port register. You can not do that faster by direct register manipulation.
However,...
4
votes
How can I set up outputs without using digitalWrite?
chrisl provided a very good reference answer. Here I am just adding a
few bits of information about the pin mapping and the pin electrical
states.
Pin mapping
One of the firs things you need when ...
4
votes
Accepted
Onboard led HIGH and LOW seems reversed
As this image from Okdo Page on LED Driving shows, there are two ways to drive an LED from a GPIO output pin:
In the Active HIGH case, a HIGH output on the GPIO will turn the LED on since that will ...
4
votes
Random "Compilation error: Error: 13 INTERNAL: exit status 1". No clue how to resolve or even what causes this error
The problem with that error message is that you are only reading the very last line. That line says "Oops, it didn't compile". The actual error message occurs before that. You need to read ...
3
votes
Accepted
Ardunio Mega/ATmega2560: Using Port F or K for both analog inputs and digital outputs
On an ATmega2560, can ports have some pins used for analog inputs but others as digtial i/o?
Yes, the ADC MUX controls the selection of the pin that is connected to the converter. This is independent ...
3
votes
Accepted
Is the shiftOut code depending on the (low) speed of an Arduino?
Some time ago, I timed digitalWrite() and direct port write commands by looping over 10,000 executions of each and timing them with millis(). I made both tests on a 16MHz Atmega 328p at 16MHz.
For ...
3
votes
Accepted
ESP 8266 reverse digitalWrite behaviour on which pins?
The esp8266 must have a pull-up on io 2 for boot configuration. The Wemos D1 boards put the LED in series with the pull-up resistor on io 2. This creates the 'reversed' LED behavior.
The large D1s are ...
3
votes
Accepted
How to increase pinout switching?
You do not need to go all the way down to assembly in order to get that
speed. You can do direct port access from your .ino file:
void setup() {
DDRA |= _BV(PA0); // pin 22 = PA0 as output
...
3
votes
Accepted
Fast digital IO
You can do this with an Uno, provided it has nothing else to do. I would
program it low-level, skipping the Arduino core since, as you said,
digitalWrite() would be too slow for this application.
Here ...
2
votes
Accepted
Replace digitalWrite with a selective bitwise operation
Personally I'd expand it out a little:
if (commandbits & (1 << i)) {
PORTB |= (1<<3);
} else {
PORTB &= ~(1<<3);
}
It's far more readable, and there are less shifts ...
2
votes
Accepted
Does direct port access interfere with PWM?
A timer interrupt will be periodically toggling the PWM bit and might do so between your port read and port write.
The easy solution is to turn off interrupts during the read/modify/write portion of ...
2
votes
Accepted
How to initialize digital output pin as low
There are two solutions:
Use the pin as a open-collector pin as in the answer of VE7JRO.
Switch the pin between input (high) and output with low. I prefer
to use the INPUT_PULLUP.
Write the output ...
2
votes
How to initialize digital output pin as low
If you have a relay that is activated by a LOW or ground path, and is deactivated
by an open circuit or HIGH signal applied, then you could try switching the pinMode
to act as the HIGH or open circuit....
2
votes
Accepted
How can I set up outputs without using digitalWrite?
Setting ports directly is a great way to learn AVR programming. I might recommend this book Make: Avr Programming.
First you need to set the direction of the port in the Data Direction Register as ...
2
votes
analogWrite(PIN, 1023) <> digitalWrite(PIN, HIGH)
I can confirm that 1023 does indeed give 100% duty cycle. I connected an output of my D1 Mini to my oscilloscope and got a steady voltage.
I can also confirm that the same voltage is output for ...
2
votes
Accepted
digitalwrite() HIGH for arduino
Different boards operate internally at different voltages. This is dictated by the main chip on the board. That main internal operating voltage is also the voltage at which the IO pins operate.
Most &...
2
votes
Accepted
Can I control solid state relay directly from arduino digital pin?
According to the datasheet there are multiple models.
Some already have an input resistor for the led (in the opto-isolator) inside the package, but some don't. For the ones that don't have a resistor ...
2
votes
Accepted
Nano: All digital pins do not output anything
Your sketch works on a Nano (clone) that I have
I am using a high-brightness white LED with a 10kΩ resistor to bring the brightness down to a bearable level, so the current drawn is about (5v-2.2v)/...
2
votes
analogRead() doesn't read more than 500Hz
You have 4 calls to analogRead() in your loop. At about 112 µs per
call, that's already taking 448 µs. Add to that the time taken by the
floating point calculations, and you are likely to end up with ...
2
votes
Why analogRead's value decreases when I decrease the value of resistor?(I use digitalWrite(high) to positive terminal of resistor)
As a complement to chrisl's answer, it is worth noting that the
datasheet of the microcontroller (here the ATmega328P), under a section
named “Typical characteristics”, has a subsection named “Pin ...
2
votes
Accepted
Read Digital Input from Arduino Pin defined as OUTPUT
If you want to know the state of the load, I suggest to put the
mechanical switch on the low-voltage side of the relay:
simulate this circuit – Schematic created using CircuitLab
The voltage ...
2
votes
Accepted
How to control PWM and digital pins at the same time over ethernet in arduino
You Arduino sketch is storing the received UDP packet in a char array
named packetBuffer, then converting this array to a String object
like this:
String datReq(packetBuffer);
The problem is that ...
2
votes
Accepted
LED doesn't completely turn off with digitalWrite(led, LOW);
if (!digitalRead(led3) && difference>=600){
digitalWrite(led3, HIGH);
}
if (!digitalRead(led4) && difference>=800){
digitalWrite(led4, HIGH);
}
if (difference>=1000){
...
2
votes
Can I use SPI-related pins as a Digital Output?
From the schematics, I can see that IO2 is for the board's blue LED. So that's probably your first problem... From this PDF, I see that IO21 is VSPIHD, Hold for Flash chips. No good. IO16 is HS1_DATA4,...
1
vote
Accepted
Use a simple LED with no digital pins to spare
Just found this:
https://forum.arduino.cc/index.php?topic=311099.0
Turns out you can use the analog pins of an Arduino UNO using this:
pinMode(A1,OUTPUT);
digitalWrite(A1,HIGH);
You just have to list ...
1
vote
Accepted
Digital Pin won't ground when set to LOW
Never directly connect a motor to an Arduino IO pin
You will destroy the Arduino.
An Arduino cannot source (or sink in your case) enough current to drive a motor, and if the motor did manage to turn ...
1
vote
digitalwrite with function parameter as parameter
You are sending the parameter Relay_Nb as a character, and then using it as an integer.
You need to turn the character into an integer - and the simplest way is to subtract the ASCII value of 0 from ...
1
vote
else if is ignored if not Serial.println anything before
Even though you read until \n, that just controls the ending of your buffered string. It does not control it's start. There may be some garbage before the command that you have not cut out. In ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
digitalwrite × 50arduino-uno × 11
analogwrite × 11
pins × 10
analogread × 5
digital × 5
serial × 4
arduino-mega × 4
arduino-nano × 4
pwm × 4
esp32 × 3
led × 3
nodemcu × 3
digital-in × 3
esp8266 × 2
motor × 2
arduino-leonardo × 2
relay × 2
teensy × 2
programming × 1
arduino-ide × 1
sensors × 1
bluetooth × 1
interrupt × 1
library × 1