10

No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons: The Arduino data pins can't source (neither sink) enough current for that to work. The inductive kickback of the motor could fry Arduino pins. The right way to do what you want to do is using an H-bridge controlled by your Arduino data pins. There are lots ...


6

First, do something simpler, and eliminate possible causes. Are you certain the NodeMCU's CPU is an 8bit PWM? If it were 9bits, it would read about 50% full scale, and 10bits would be about 25% of digitalWrite (which is what I think I can see on the photo). Swap the analogue meters around, and see if the difference is consistent with the pin, or consistent ...


4

I just tried to time digitalWrite() against direct port access with the following code: void setup() { uint16_t overhead, start, end; Serial.begin(9600); TCCR1A = 0; TCCR1B = 1; // Time digitalWrite(). overhead = 7; cli(); start = TCNT1; digitalWrite(2, HIGH); end = TCNT1; sei(); Serial.print("digitalWrite():...


3

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 of the digital pin control. Cheers! PS: See the Arduino core source code for further details on the ADC MUX control registers.


3

I just tried what you suggest, and it works fine, with only one (big) caveat: you can only power this way very low power motors. I did this to drive the linear motor that moves an HDD head assembly. This motor works perfectly fine with less than 18 mA. Note that I switch the Arduino pins between the HIGH and LOW states, not going through INPUT. Setting ...


2

Yes, setting a pin to OUTPUT and setting it LOW effectively connects the pin to ground (via a few ohms of resistance). There's a couple of things wrong with your code, though, which you should address: Use digitalWrite() not analogWrite(). analogWrite(pin, 0) is effectively the same as digitalWrite(pin, 0), but it's ambiguous to someone reading your code....


2

Every other value than 0 or LOW will result in setting the pin to HIGH. In the following I explain why: The function digitalWrite() can be seen in the file hardware/arduino/avr/cores/arduino/wiring_digital.c. The important lines here are: if (val == LOW) { *out &= ~bit; } else { *out |= bit; } As you can see, it checks, if the given value (...


2

I don't think that's going to work. You'll be better off using a cheap module like the Pololu Pololu DRV8838 which implements a MOSFET H-bridge. (Note: I'm not related in any way with Pololu.)


2

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 to mess around with. Plus the AVR has bit set and bit clear operations which that will make use of, especially since it's now using literal values. You could ...


2

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 your port update sequence. This could cause a stretched PWM cycle. If you don't turn it off, you'd just glitch the PWM - creating an extra, short cycle. Which ...


2

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 value before setting the pinMode. All the microcontrollers of the AVR family (ATtiny and ATmega chips) allow to set the output value before setting the pin as ...


1

As Jot wrote, you cannot simply route a signal from pin to pin inside the chip/Arduino. So - unless you redesign the PCP, which would be the cleanest way, or use jumper wires, which is not so clean - you are down to using software PWM. There are also libraries for this, if you don't want to write this yourself, for example the SoftPWM library. These ...


1

The boot setup pins have pull-up on board (0, 2) and pull-down (15) to ensure the correct boot. io 0 (D3) is additionally wired to the reset circuit controlled over USB to put the esp8266 into bootloader a.k.a. flashing mode. io 0 must be HIGH for normal boot, io 2 must not be LOW (can float according to spec). If you attach a device to this pins, the ...


1

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. const byte pin = 2; void setup(){ // Define the pin as INPUT_PULLUP until you are ready to use it. pinMode(pin, INPUT_PULLUP); } void loop(){ ...


1

As fas as I know, by default digital pins are set as inputs. Arduino has internally only pull-up resistors, which you can use in that way: digitalWrite(pinOut[i], HIGH); in first setup() line (without pinMode(pinOut[i], OUTPUT);). If you need LOW state on start-up (pull-down resistors), you have to use an external resistor.


1

If you like both portability, readability and performance there are a few libraries (for instance Arduino-GPIO): #include "GPIO.h" GPIO<BOARD::D11> data; // Setup data.output(); // Manual loop unrolling for speed. Could ask the compiler to do this // Member function write() data.write(commandbits & 0x80); data.write(commandbits & 0x40); ...


1

One method is to use interrupts with a state machine. Here is a minimal example: Master #define pin 10 // connect to slave digital input pin void setup(){ pinMode(pin,OUTPUT); digitalWrite(pin,LOW); } void loop(){ if( // insert your condition to trigger the slave Arduino ){ digitalWrite(pin,HIGH); delay(10); // short delay digitalWrite(pin,LOW); ...


1

The problem you are seeing here is that the Arduino can provide nowhere near as much current through I/O pins as it can power. Quoting from the Arduino website: DC Current per I/O Pin: 40 mA This means that each pin can power maybe a couple of LEDs, and that's it. Additionally, motors provide "back-EMF": When opening (cutting power) an inductive load (e....


1

A digital IO pin is only capable of powering an LED or an incredibly low powered device. It is not suitable for powering meaty RF modules. Instead you need to control the power to your module using a P-channel MOSFET as a High-Side switch. For instance, assuming a 5V module with built in 3.3V LDO: simulate this circuit – Schematic created using ...


1

I think the problem is, that your delays are just too short, so you see the blinking not as blinking, but as a dim lit led. Maybe you can try the following code: void loop() { while (keepgoing == 1) { digitalWrite(ledone, HIGH); digitalWrite(ledtwo, LOW); delay(500); digitalWrite(ledone, LOW); digitalWrite(ledtwo, HIGH); delay(500); } } Is ...


Only top voted, non community-wiki answers of a minimum length are eligible