Hi, i am fairly new to arduino and i'am building a quadcopter with it. It has been a very educational project and i am coming to an end to see my quad flying.
But i've ran into a problem that i am running out of digital pins (analogs are also in use). And i still have 4 esc's to drive.
But luckily i have 2 PCF8574's lying around and esc's are expecting a pwm signal from 1000µs to 2000µs.
I've tried the code as follows but no luck, the three of the esc's are geting around a ~1300µs pulse (don't have an oscilloscope just guessing by motor speed) and one of them doesn't get any signal at all
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h>
#include "PCF8574.h"
#define PCF8574_ADDRESS 0x20
PCF8574 pcf20(PCF8574_ADDRESS);
RF24 radio(9, 10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
int throttle = 1000;
void setup() {
Wire.begin();
pcf20.begin();
pcf20.write8(LOW);
// put your setup code here, to run once:
Serial.begin(57600);
radio.begin();
radio.setRetries(15, 15);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, pipes[1]);
radio.startListening();
}
void loop() {
// put your main code here, to run repeatedly:
while ( radio.available() ) {
radio.read(&throttle, sizeof(int));
}
Serial.println(throttle);
pcf20.toggle(0); // P0 high
delayMicroseconds(throttle);
pcf20.toggle(0); // P0 low
delay(2);
pcf20.toggle(1); // P1 high
delayMicroseconds(throttle);
pcf20.toggle(1); // P1 low
delay(2);
pcf20.toggle(2); // P2 high
delayMicroseconds(throttle);
pcf20.toggle(2); // P2 low
delay(2);
pcf20.toggle(3); // P3 high
delayMicroseconds(throttle);
pcf20.toggle(3); // P3 low
delay(2);
//This works fine with digital pins
/*
digitalWrite(pwmPin1, HIGH);
delayMicroseconds(throttle);
digitalWrite(pwmPin1, LOW);
delay(2);
digitalWrite(pwmPin2, HIGH);
delayMicroseconds(throttle);
digitalWrite(pwmPin2, LOW);
delay(2);
digitalWrite(pwmPin3, HIGH);
delayMicroseconds(throttle);
digitalWrite(pwmPin3, LOW);
delay(2);
digitalWrite(pwmPin4, HIGH);
delayMicroseconds(throttle);
digitalWrite(pwmPin4, LOW);
delay(2);
*/
}
My question is can you generate a pwm signal with PCF8574?
(Using an arduino uno).
Thanks in advance