I have two cores, but recently , i found all the pins are not able to work.Is this related my firmware or hardware ? but i havent chang the firmware as i remember. if the issue comes from the hardware which is strange happing on both.
Btw, the status LED is breath and successfully connected to the Local Cloud.
Below is the simplest code of application.cpp.
#include "application.h"
/* Function prototypes -------------------------------------------------------*/
int tinkerDigitalRead(String pin);
/* This function is called once at start up ----------------------------------*/
void setup() {
//Register all the Tinker functions
Spark.function("digitalread", tinkerDigitalRead);
// Configure the pins to be outputs
pinMode(D0, OUTPUT);
// Initialize both the LEDs to be OFF
digitalWrite(D0, LOW);
}
/* This function loops forever --------------------------------------------*/
void loop() {
delay(1000);
digitalWrite(D0, HIGH);
}
int tinkerDigitalRead(String pin) {
//convert ascii to integer
int pinNumber = pin.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7)
return -1;
if (pin.startsWith("D")) {
pinMode(pinNumber, INPUT_PULLDOWN);
return digitalRead(pinNumber);
} else if (pin.startsWith("A")) {
pinMode(pinNumber + 10, INPUT_PULLDOWN);
return digitalRead(pinNumber + 10);
}
return -2;
}
First, since you don’t give a lot of clues what kind of external circuitry you’ve attached to your pins, it’s not clear what signal you want to digitalRead.
Second your statement pinMode(pinNumber, INPUT_PULLDOWN) would explain why you always get zero readings, because the INPUT_PULLDOWN does its job, to attache a pull down resistor to the pin which will pull any open/floating pin down to LOW level.
But then it’s odd that you get HIGH readings for D3, D5 and D7, unless you have got some ext circuitry - which you haven’t said anything about - causing that.
If you only want to test if digitalRead reports back the state you earlier set via a digitalWrite (e.g. the statements in your setup() and loop()) then you’d need to remove the pinMode statement from your tinkerDigitalRead function - for the reason stated above. pinMode(Dx, INPUTxxx) does set the pin in a way that any state set while it was set as OUTPUT pin will be lost and will either produce floating/random (for INPUT) or always LOW (for INPUT_PULLDOWN) or always HIGH (for INPUT_PULLUP) readings when the pin has no ext signal attached.
But if you leave the pin set as OUTPUT, for quite a while now the digitalRead function will give you the state you’ve set via digitalWrite.
Also, the Tinker app specifically sets the pin mode when a function is called, so you can’t set a digital output to a value and then read back that value on the same pin.
This will return the floating state of D0, not HIGH.
My bad, I am wrong understanding the Tinker function ,and never used it before, I just simply copy the Tinker function into my code for testing purpose for convenience, But not read the function carefully.
@ScruffR, I remvoed all circuit just for troubleshooting.