Problems on ESP8266 programming based on Arduino IDE for ESP8266 - arduino

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.

Related

trouble triggering relay with Bluetooth on an Arduini Mega

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().

Not able to upload to my Arduino Micro board

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.

Wire.endTransmisson crashing when building Arduino Library

I am trying to have a constructor set up the pins on the external chip I am using to be outputs. To do so I need to do an I2C transaction.
Below is code that is currently in the constructor. With the Wire.endTransmissonline in the code, it crashes. With it omitted it works. But I feel that it should be in there and something else is going on. Is there something I am missing here?
HID::HID(){
Wire.begin();
I2Cflag = 1;
Wire.beginTransmission(0x41);
Wire.write(0x03);
Wire.write(0xF3);
Wire.endTransmission(); //When omitted, it works!
I2Cflag = 0;}

what does type error mean in Arduino

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.

How can you check for already stored variables on an Arduino Uno?

I have a program I want to make which will ask to see whether a variable already exists. If it does, it displays it, if it does not, it creates it and stores it in the Arduino using the PROGMEM command. Can someone explain more about PROGMEM and how to make the program I'm talking about?
Generally speaking if you are creating any variables in functions they are existing only there when function is closed all variables are deleted. If you want to keep them alive try to create global variables or use static before it;
like here
static int myvariable;
And here is answer for your question
if (myvariable!=NULL)
{
printfucntion(myvariable);
}
solution for eeprom
EEPROM Read
Reads the value of each byte of the EEPROM and prints it to the computer.
#include <EEPROM.h>
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
//move to next address of the EEPROM
address = address + 1;
// there are only 512 bytes of EEPROM, from 0 to 511, so if you are
// on address 512, wrap around to address 0
// if you have arduinoMega probably there is more eeprom space
if (address == 512)
address = 0;
delay(500);
}
I hope I helped.
This is a pretty stale question, and one that's not so popular. BUT is a valid question. In php, I am all the time using isset() to test for variables' existences. So, perhaps the OP is coming to embedded / C programming from the make-love-not-war world of php, where anything goes and isn't accustomed to the extremely literal and formal country of C.
As pointed out here, C language has #ifdef and #ifndef conditional defines that are often used for the exact purpose of testing if something is defined. To better understand the nuance of this usage, one should probably visit Programmers.SE and inquire about professional philosophy about conditional defines.
Me? I'm researching permanent variable storage on an Arduino via the EEPROM. Here are two different excellent articles. And about #ifdef's? I am just a lowly software engineer and save that for software architects. ;-) I have never intentionally implemented them, just see those a lot.
And a literal answer to the OP's question is: query the variable and try to use it. The Arduino's IDE compiler will scream if it is not defined.
Its simple , Just you need to Declare a variable.just compare with array of elements,you wanna compare with. If array element and enter element are present display using Serial.print() statement else you store it in array of buffer accumulating it. Display it.
As you are doing single link list

Resources