I am working on the Adafruit Feather Huzzah ESP8266 and I would like to add an internal pull-up to a push button. When I do the pull-up manually with a resistor, my wiring works perfectly but when I add an internal pull-up using the following line in my Arduino IDE code, it does not work properly.
pinMode(BOUTON,INPUT_PULLUP)
Here is my full code:
const int LED = 13;
const int BOUTON = 16;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BOUTON, INPUT);
}
void loop()
{
int etat = digitalRead(BOUTON);
if(etat==LOW)
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
}
Here is my wiring with the pull-up:
Here is my wiring with supposed internal pull-up:
When writing a program, you had erroneously assumed that GPIO16 had a pullup resistor. It does not.
At startup, pins are configured as INPUT.
GPIO0-GPIO15 can be INPUT, OUTPUT, or INPUT_PULLUP. GPIO16 can be INPUT, OUTPUT, or INPUT_PULLDOWN_16. It is also XPD for deepSleep() (perhaps via a small capacitor.)
Note that GPIO6-GPIO11 are typically used to interface
with the flash memory ICs on most esp8266 modules, so these pins
should not generally be used.
Reference: http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations
Have a look at Adafruits overview of the Feather HUZZAH ESP8266. You are able to use the GPIO's 0, 2, 4, 5, 12, 13, 14, 15, 16 but:
These pins are general purpose and can be used for any sort of input
or output. Most also have the ability to turn on an internal pullup.
Many have special functionality.
Having detailed look at GPIO 16 shows us it is very special. The GPIO is used to wake up the controller from deep sleep. Therefore it is the only GPIO have a built in pull down resistor which is described in this beginners guide. This allows to directly connect with RESET. This means GPIO 16 has no pull up resistor like assumed.
Related
I'm planning to make a Bluetooth controlled relay. but i keep having problems triggering the relay with my Bluetooth entries.The data i write on my phone is displayed in the serial monitor but i just cant get the relay to turn off or on.i am using a single channel relay module and the HC-06 Bluetooth module.
can someone please tell me what the problem is?? this is driving me crazy. my Bluetooth module is connected to TX and RX respectively and my relay is connected to pin 13 of my arduino mega.
Thank You in advance!
#include <SoftwareSerial.h>
SoftwareSerial bt(1,0);
int RelayStateOn =0;
void setup() {
bt.begin(9600);
pinMode(13,OUTPUT);
}
char val=bt.read();
void loop() {
if(bt.available()) {
bt.println(val);
}
if(val==1) {
digitalWrite(13,HIGH);
}
else if(val==0) {
digitalWrite(13,LOW);
}
}
Firstly, you don't have a call to read from the bt in the loop anywhere. You have a call to bt.read() at global scope, so val gets a value that was read before anything was ready to read. So it most likely gets a -1.
You also have a call to avaialable before you have a call to print which implies that you don't understand what available is for. It tells if there is more available to read. So that should be around the line in loop that you're going to add that reads from bt not the one that prints to it.
To start with, where you have the bt.println(val), change that to val = bt.read().
I am using the ESP32 dev board with the Arduino and wish to use an interrupt to determine if a master device has sent the Slave Select flag to the ESP32.
Here is what I've tried so far
1)
#define SS 34
void enableSend() {
Serial.println("SS Enabled");
}
void setup(){
pinMode(SS, INPUT);
attachInterrupt(digitalPinToInterrupt(SS), enableSend, RISING);
}
2)
#define SS 34
void IRAM_ATTR enableSend() {
Serial.println("SS Enabled");
}
void setup(){
pinMode(SS, INPUT);
attachInterrupt(digitalPinToInterrupt(SS), enableSend, RISING);
}
I've used both versions without digitalPinToInterrupt.
What do I need to do to get the interrupts to work? Currently, the enableSend function does not get called when pin 34 is set to high.
If it helps, here is the pinout for the ESP dev bord that I have.
You definitely need the IRAM_ATTR (see 2) in order to place the ISR (interrupt service routine) in the Internal RAM (IRAM) of the ESP32.
I think that the Serial.println("SS Enabled"); that you wish to execute in the ISR
is too complex for an ISR.
The ESP32 stops the regular execution flow to execute the ISR, which is supposed to
be executable in minimal time, only a few CPU instructions.
Sending data over the Serial Port takes quite a few milliseconds, which is too long for an ISR.
You can use the ISR to change a variable / flag that you evaluate within the regular
flow of execution, that way you minimize the risk of messing up the devices flow of
execution... you can send the "SS Enabled" from there.
I decided to use Arduino IDE for ESP8266 to program on my ESP8266, targeting to read data (bytes array from a TTL camera). ESP8266-01 (8Mbits Flash ROM) has 8 pins so I decided to use GPIO16 (TXD) and GPIO2 (RXD) as SoftwareSerial pins to achieve this. But the ESP8266 printed an exception and I am not sure what happened to it.
So I have a few question about this crash.
I want to know whether I can run SoftwareSerial on ESP8266 (ESP8266 has 2 UARTs, Serial0 for Serial print and we could not send data through Serial1), so I decided to use SoftwareSerial.
I don't know what the exception info means for I can't understand assembly language.
I read documents on Github for Arduino IDE for ESP8266, but I don't understand well about the pin definitions on ESP8266 when programming with Arduino IDE. For example, when using GPIO16 (TXD) and GPIO2 (RXD) as SoftwareSerial, we might use Constructor SoftwareSerial Camera(int Pin1, int Pin2). I want to know what the corresponding Pin1 and Pin2 for GPIO2 and GPIO16) is. The document really confused me.
Here is my key code.
#include <Arduino.h>
#include "camera_VC0706.h"
#include <SoftwareSerial.h>
HTTPClient httpClient;
//define camera and bytes array, I am not sure whether the pins are correct or not
int rxPin=2;
int txPin=16;
SoftwareSerial cameraSerial(rxPin,txPin); //RX,TX
camera_VC0706 Camera = camera_VC0706(&cameraSerial);
//take photo
bool takePhoto() {
byte time=0;
writeRawSerial(F("<STATUS>WAITING</STATUS>"),true);
while(!Camera.begin(115200)) {
if(+time<=5){//try 5 times
writeRawSerial(F("."),false);
} else {
writeRawSerial("",true);
writeSerial(F("<STATUS>NO_CAMERA</STATUS>"));
return false;
}
}
writeRawSerial(F("<STATUS>CAMERA_ON</STATUS>"), false);
writeRawSerial(F("<VERSION>"), false);
writeRawSerial(Camera.getVersion(), false);
writeSerial(F("</VERSION>"));
Camera.setImageSize(VC0706_320x240);
if (!Camera.takePicture()) {
writeSerial(F("<STATUS>TAKE_PHOTO_FAIL</STATUS>"));
return false;
} else {
byte imgSize = Camera.frameLength();
writeSerial(F("<STATUS>TAKE_PHOTO_SUCCESS</STATUS>"));
writeRawSerial(F("<IMAGE_SIZE>"),false);
writeRawSerial(String(imgSize,DEC),false);
writeSerial(F("</IMAGE_SIZE>"));
freeHeap();//It was defined, but not key function, only for showing free heap of esp8266
imgBuffer=Camera.readPicture(imgSize);
freeHeap();
Camera.resumeVideo();
writeSerial(F("<STATUS>SAVE_PHOTO_SUCCESS</STATUS>"));
return true;
}
}
Thank you for reading my questions.
You need to add the standard Arduino functions of setup() and loop() or it won't know where to start.
If you have a look at the example sketches you should be able to get something running, and then you can start adding your takePhoto code.
So, the stack trace shown is pretty standard for any system, and it gives you pretty much everything you need to track it down - It is not assembly code, it is hexadecimal addresses of your binary.
First, you have an Exception 28 - If we look at the ESP8266 Reference, you can see 28 means you either have a bad pointer, or you're trying to access non-cached data from an interrupt/cache is turned off.
Next, you have an address, epc1. This is where the code crashes, which is a hexadecimal address to the binary you uploaded. Also, ctx: cont is helpful, as it indicates the program crashed in your code and not the system code.
You also have excvaddr, which is the addressed you tried to access, 0x10.
Given that, you almost certainly have a NULL pointer somewhere in your code that you are dereferencing. You should use the ESP Exception Decoder to determine what line has the offending crash and bad pointer usage.
In regards to using the software serial - You'd just use the pin numbers on the datasheet. GPIO 14 would be number 14 in the constructor. I found it worked, but caused very bizarre crashes in the production products I worked with after 1+ days of usage, so do not recommend it at all. We ended up using Serial1 for debug printing, and freed up Serial0 for general UART communications - Way more reliable.
I uploaded the following program to my Arduino micro:
#include <Mouse.h>
int buttonPin;
void setup() {
pinMode(buttonPin, INPUT);
Mouse.begin();
}
void loop() {
if(digitalRead(buttonPin) == HIGH) {
Mouse.click(MOUSE_LEFT);
}
}
First of all, yes I already know that I haven't defined buttonPin (I realized after the fact) but, this is the code as I uploaded it. Now when ever I plug my Arduino in to try to upload a program it spam clicks, causing the Arduino IDE to overload and not upload my program. It should also be noted that one time it also overloaded my computer forcing me to unplug the Arduino and reset my computer. My question is: #1: is there any way to actually fix the Arduino (I also have an Arduino Uno if I need to hook it up to that for some reason) and #2: when or if I get the Arduino working again, how would I fix my code. (I'm guessing the answer to #2 would be changing int buttonPin; to int buttonPin = 2)
Connect pull-down resistor to pin 0 because global variables are initialized to theirs default values. This should stop spam from mouse and it should be possible to upload code.
Otherwise you need another Arduino as Arduino ISP and upload new code over 6pin serial interface.
I am building a weather station using my friend's code. However, he an older verison of Arduino and I'm having trouble figuring out why. I am new to programming, so I don't know what "'dht' does not name a type" means? I'm using Arduino 1.04 and my friend coded his weather station on Arudino 0022. My question is, why isn't my verification able to compile? What am I doing incorrectly?
Here's my code:
#include <dht.h>
dht DHT;
#define DHT22_PIN 2
#include <Wire.h>
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 3; // Oversampling Setting
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
short temperature;
long pressure;
void setup()
{
pinMode(2, INPUT);
Wire.begin();
bmp085Calibration();
Serial.begin(115200);
analogReference(INTERNAL);
}
void loop() {
// READ DATA
float bat_read=analogRead(6);
//bat_read = analogRead(BAT_voltage);
float chk = DHT.read22(DHT22_PIN);
// DISPLAY DATA
Serial.print(bat_read, DEC);
Serial.print(", ");
Serial.print(DHT.humidity, 2);
Serial.print(", ");
temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
Serial.print(temperature, DEC);
Serial.print(", ");
Serial.println(pressure, DEC);
delay(1000);
}
The errors are:
error: 'dht' does not name a type
sketch_jul05a.ino: In function 'void loop()': error: 'DHT' was not declared in this scope
About your specific bug you should
'dht' does not name a type
That means you have the word dht that is not at a place where the compiler could understand what you mean.
how do i change it to a type?
You do not want to change it into a type, you want to solve the compiling issue you're getting.
what does a type mean?
You should read the K&R on the subject. A type is a rule that constraints you into making code that is coherent.
You should copy in your question the full error you're getting, for us to better help you.
Let's assume the error is on the following line:
#include <dht.h>
dht DHT;
The compiler does not know what is the dht, as it has never seen that being defined before. I assume, dht.h shall be a header to be included that needs should contain dht type definition. You should look if you have dht.h in your filesystem, and push it in your sketch's directory. And finally change the #include <dht.h> into #include "dht.h", so it looks up the dht.h in your local directory.
EDIT: I'm sorry I don't think I can't help you here more than what I just said. The problem is that you don't understand what I'm telling you to solve your problem, and explaining it to you would be giving you a C programming lesson. So you should first begin to read the K&R, go to some C/C++/Arduino programing courses (maybe in your local hackerspace?), and/or ask your friend to help you out and explaining to you what is happening.
I had this exact same issue yesterday while updating a sketch using the DHT22 sensor that was written in Arduino 0022. I was trying to edit it in the Arduino 1.0.5 IDE. Multiple compile errors, particularly with the function millis(). I think it might have worked if I'd just opened the 0022 IDE, but I thought it was time to bring the sketch into this decade ;)
I downloaded the Adafruit DHT22 library from Github and re-wrote the sketch slightly to use the library's methods. It was pretty much drop-in. There is an example sketch included with the library that you can derive to make everything fit.
In my sketch, I got things going with:
#include "DHT.h"
#define DHTPIN 7 // what pin we're connected to on the Arduino UNO
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
A difference between the old version and the updated version was the 'dht.begin();' statement in the setup block.
The Adafruit library isn't quite as robust as the previous library I'd been using, particularly with error handling, but it just worked after maybe 45 minutes of fiddling.
May doG help me if the XBee library stops working in a future Arduino IDE release!
A 'type' describes what your variable is. Like an integer (5), a string("Hello world"), a character("a"), a boolean (true or false), or a float (3.1415).
It looks like 'dht' is supposed to be a type but the arduino IDE does not recognize it since it isnt a normal type. This should be solved by importing a library that creates that type. Then the arduino can recognize it.
This is where your "#include " comes in. I would recommend changing it to "#include "dht.h".
Also, double check to make sure that dht.h is indeed a file that the arduino can access.