So I think I'm doing fairly well so far, have the arduino IDE installed, add the ESP8266 module, manage to get an LED blinking on and off. Time to connect to the WIFI and do some stuff.
Unfortunately, it all falls apart then. I get errors about undefined references to wifi_set_opmode, wifi_station_set_config and wifi_station_connect. Now, this isn't my first rodeo with C so I started looking for documentation on these functions and how they are included but can find nothing except people apparently quite happily using them. I've tried adding all sorts of #includes but nothing helps so far. So time to ask for a little help.
Here is the code I am trying to run (pretty uneventful)
#include <user_interface.h>
#define LED_1 13
void setup() {
// put your setup code here, to run once:
pinMode(LED_1, OUTPUT);
const char ssid[32] = "qqqq";
const char password[32] = "wwww";
struct station_config stationConf;
wifi_set_opmode( STATION_MODE );
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
wifi_station_set_config(&stationConf);
wifi_station_connect();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_1, HIGH);
delay(500);
digitalWrite(LED_1, LOW);
delay(500);
}
My board selection is "Generic ESP8266 module"
Here are the errors.
sketch\blinktest.ino.cpp.o:(.text.setup+0x8): undefined reference to `wifi_set_opmode(unsigned char)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x10): undefined reference to `wifi_station_set_config(station_config*)'
sketch\blinktest.ino.cpp.o:(.text.setup+0x14): undefined reference to `wifi_station_connect()'
You need to notice that Arduino is not C, it's based on C++. So add your inclusion like below to use C SDK based functions.
extern "C" {
#include "user_interface.h"
}
Arduino IDE has code examples on menu
File > Examples
There is also example called WiFiWebClient where you need to change only your wifi ssid and password.
Save it to a new folder and you can make http requests to any site on Internet by modifying the address on the example.
Start from the examples of the manufacturer so you don't need to rely on outdated / partial tutorials.
Related
I'm pretty new to Arduino and especially ESP32. But - before I receive the tip "use an Arduino" - I decided to go for the ESP32 because of the size and the capability to connect it to the WLAN.
However, I am trying to build some control box for my terrarium which should - in the first design - steer various lamps and the rain pump via remote controlled outlets. For this I got an ESP32 NodeMCU, a RTC time module (which seems to work quite fine) and a 433 Hz receiver/sender set.
I followed several tutorials regarding the wiring and uploaded the example files to the ESP32. No matter which pin I connect the Receiver to (I need to connect the receiver first in order to read out the signals of the 433 Hz control which came with the outlets) I won't receive any signals on the receiver.
I embedded the library RCSwitch and I tried to configure my switch as follows (here with PIN 13 as example - I tried several other pins as well):
mySwitch.enableReceive(13)
As I read in some other blog, there might be the need to convert the pin number to its interrupt address, so I tried the following:
mySwitch.enableReceive(digitalPinToInterrupt(13))
The result is always the same: dead silence on the serial monitor (except the boot messages, etc.).
Am I using the wrong library or what am I doing wrong here?
I read that there should be a library called RFSwitch, but the only version I found only features the 433 Hz sender, not the receiver.
I would be really grateful for any hint concerning this issue - I'm pretty stuck here for many hours now...
I know this is pretty old and maybe you've resolved the issue by now but maybe it will help others. I had the same issue and what helped me was to set the pinMode:
pinMode(GPIO_NUM_35, INPUT);
mySwitch.enableReceive(digitalPinToInterrupt(GPIO_NUM_35));
Have been successful with RCSwitch today on ESP32 Dev Board and a 433MHZ receiver and sender. Here is what I have been stumbling on my journey.
Connecting the receiver (requires 5V)
You can use the ESP32-VIN for 5V if the Micro-USB is used to supply power
You may connect the Receiver-DATA to any ESP-32-Input-PIN BUT you might damage your ESP32 since it only allows ~3.3V
I tried first with some "makeshift" level shifting through resistors but I guess it lowers speed too much => A proper level-shifter (5V => 3.3V) might work out well
When referencing the PIN "xx" I have been just using the PIN-Number "Dxx" written on the ESP32-Dev-Board
You may connect an antenna of ~17.3cm to improve range
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#define RXD2 27
void setup() {
Serial.begin(115200);
Serial.print("Ready to receive.");
mySwitch.enableReceive(RXD2);
}
void loop() {
if (mySwitch.available()) {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.print( mySwitch.getReceivedProtocol() );
Serial.print(" / ");
Serial.println( mySwitch.getReceivedDelay() );
mySwitch.resetAvailable();
}
}
In your RC and Outlet can be configured by DIP-Switches you might not need to connect the receiver overall - you can directly insert the DIP-Switches levels in the RCSwitch-Library
Connecting the sender (is fine with just 3.3V)
You can use the ESP32-3.3 to supply power
You may want to double check the PIN-Labels - I got confused because the DATA-Label was off and first interpreted as GND | DATA | VCC instead of GND | VCC | DATA
You may connect an antenna of ~17.3cm to improve range
#include <Arduino.h>
#include <WiFi.h>
#include <RCSwitch.h>
#define TXD2 25
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(115200);
// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(TXD2);
// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
// Optional set pulse length.
mySwitch.setPulseLength(311);
// Optional set number of transmission repetitions.
// mySwitch.setRepeatTransmit(15);
}
void loop() {
/* See Example: TypeA_WithDIPSwitches */
mySwitch.switchOn("01010", "10000");
Serial.println("Switch On");
delay(10000);
mySwitch.switchOff("01010", "10000");
Serial.println("Switch Off");
delay(10000);
}
I have not yet used sender or receiver while WiFi being active. Though I have been reading about issues while WiFi is active and receiving / sending via 433Mhz.
The sender must have 5 V supply to go far, and it has not output pin which can damage the ESP32, and the receiver. Instead, must be connected to 3.3 V because it has an output which goes to ESP2 (3.3 V supply) and the output of the receiver must not be more than 3.3 V, so as not to damage the GPIO input of ESP32.
ESP32
The data sender(input) goes to: GPIO 5: pinMode(5, OUTPUT)
The data receiver (output), goes to GPIO 4: pinMode(4, INPUT)
Sender supply: 5 V
Receiver supply: 3.3 V (not to damage ESP32 GPIO 4)
I am trying to get the data from GY-NEO6MV2 GPS and I've tried every solution, but I stil get error:
C:\Users\Szymon\Documents\Arduino\libraries\NewSoftSerial\NewSoftSerial.cpp:43:10: fatal error: WConstants.h: No such file or directory
I use the most simple possible code, it only includes the library and does nothing else, so it's not a problem with my code.
None of the solutions from the internet is working, anybody has an idea why it is not working?
NewSoftSerial is Arduino library for AVR ATmega MCU. It can't be used with other MCU Arduino platforms.
Okay, thank you Juraj for help.
I used the Serial1 to obtain data from the GPS and it worked.
The code if someone also has that problem:
void setup() {
Serial1.begin(9600);
SerialUSB.begin(9600);
}
void loop() {
if (Serial1.available()) {
char outp = Serial1.read();
SerialUSB.print(outp);
}
}
So i am working on a rc car which is equipped with a gps module(NEOBLOX 6M) and a geiger counter(Diy Kit). The data read by sensors is to be displayed on a c# application using xbee modules. On my C# application i am using a label to be updated according to the data received, but the problem here is that the data from gps module and geiger counter both is displayed on a single label, i want to display data from different sensors on individual labels or textboxes.
GPS Module:http://wiki.sunfounder.cc/index.php?title=Ublox_NEO-6M_GPS_Module
Geiger Counter:https://www.ebay.com/p/US-Assembled-DIY-Geiger-Counter-Kit-Nuclear-Radiation-Detector-Arduino-Tube-2018/14014157093?iid=273049840938
Well have you heard the term ROS?
Your description isn`t very clear. So I dont have much idea on your system design.
No matter all the sensor is connected to arduino or partially connect to arduino and partial connect to PC.
You can use ROS Arduino node and ros node to read the sensor and publish with ROS-time. You can follow the method in the link below
http://wiki.ros.org/rosserial_arduino/Tutorials
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);
char hello[13] = "hello world!";
void setup()
{
nh.initNode();
nh.advertise(chatter);
}
void loop()
{
str_msg.data = hello;
chatter.publish( &str_msg );
nh.spinOnce();
delay(1000);
}
You can change this str_msgs to any msgs type that you sensor is giving, Eg giger counter is double. Or sensor_msgs/NavSatFix (gps message in ros) , or your position is nav_msgs/Odometry
Whenever there is a reading, just publish them with a correct time stamp.
Publish all the info to the C# ros node for display. Usually, there would be a lot of data, so you shouldnt use textboxes. Instead you should be able to plot a heat map or energy map
https://github.com/siemens/ros-sharp follow this for ROS C# interface
I am trying to control a servo motor on a timer using buttons and the ATtiny85. I am able to use the ATtiny to make an LED blink at the push of a button but once I include the servo library my code does not work.
I have tried using the Servo.h library and the Servo8Bit.h library but neither work. I thought that the issue might be coming from one timer being used for two different things so I went into the Servo8Bit.h and Servo8Bit.cpp source files and changed all Timer0 to Timer1 and all TCCR0B to TCCR1B.
I receive these error messages when I try to upload my code:
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp: In static member function 'static void ServoSequencer::setupTimerPrescaler()':
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp:493:9: error: 'TCCR1A' was not declared in this scope
TCCR1A = 0;
^
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp:498:13: error: 'TCCR1B' was not declared in this scope
TCCR1B &= ~(1<< CS02); //clear
^
Using library Servo8Bit-master in folder: /private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master (legacy)
exit status 1
Error compiling for board ATtiny25/45/85.
The expected result is that after uploading the code I will press a button. After a specified amount of time, 10 minutes in this case, the motor should move but the code doesn't even upload.
All you have to do is comment/uncomment the right choice in the header file Servo8Bit.h:
//Options
//pick one, comment out the other one out:
//#define USE_TIMER0
#define USE_TIMER1
and it'll be compiled with correct settings and so on.
You've probably tried to change 0 to 1 everywhere and failed because the timer0 and timer1 aren't the same. The timer1 doesn't have two control registers A and B unlike timer0.
I am writing a small test program that attempts to perform a serial.write() followed by a serial.read() within an ISR. The code will eventually be used to prompt an external GSM shield to send an SMS on a regular basis.
ISR(TIMER2_OVF_vect) {
Serial.println("AT+CMGS=\"0123456789\""); // Tell Sim900 To prepare sms to number 01...
while(Serial.read()!='>'); // Wait for Sim900 to respond
Serial.print("A text message"); // the SMS body
Serial.write(0x1A); //Confirm send instruction
Serial.write(0x0D);
Serial.write(0x0A);
}
}
What I have found after a lot of testing is that Serial.read() within an ISR is not capable of reading a live serial prompt, instead it will only read any input that was buffered before the ISR was triggered.
Is there any way around this?
The only solution I have found is to place this code instead within the main loop(). But I want to send the SMS using a timer interrupt.
Thank you
You need to place the code in the loop() but using an IF:
float toBeSent = interval;
loop() {
if (millis() > toBeSent) {
Send();
toBeSent = milli() + interval;
}
}
interval is your sending interval in milliseconds.
I had a similar problem a while ago which I managed to resolve by using the Arduino SoftwareSerial library instead of the hardware based Serial.read.
There are some overheads associated with using SoftwareSerial, and you can only read one port at a time, so I leave it up to those with a better understanding of the Arduino platform to tell you if this is a good idea, but one of the benefits of this library is that you can use it within an ISR.
To use the SoftwareSerial library, add the following two lines of code at the top of your sketch remembering to replqce the rx_pin and tx_pin with the corresponding pin values you want to use:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(rx_pin, tx_pin);
Then replace the key word Serial throughout your sketch with mySerial (or whatever name you have chosen to give your SoftwareSerial instance).
An important thing to keep in mind when using SoftwareSerial is that you can only use certain pins on the Arduino so read the documentation first.
If you wanted to live dangerously you could enable interrupts inside the ISR and use a flag to prevent reentry.
int flag=0;
ISR(TIMER2_OVF_vect) {
flag = 1
if (flag){return;}
sei();
Serial.println("AT+CMGS=\"0123456789\""); // Tell Sim900 To prepare sms to number 01...
while(Serial.read()!='>'); // Wait for Sim900 to respond
Serial.print("A text message"); // the SMS body
Serial.write(0x1A); //Confirm send instruction
Serial.write(0x0D);
Serial.write(0x0A);
}
flag = 0;
}