I am trying to use a hc-05 module for the first time and I have some problems: I already had a hard time finding the right pins for the rx and tx pin that g finally put on rx -> pin0 (rx) and tx -> pin 10.
I can send data from the hc-05 to the phone but if I send from the phone to the hc-05 I get weird characters. Here is my code and the configuration. Thank you for your help. [configuration image][1]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 0); // RX, TX
void setup() {
Serial.begin(9600);
pinMode(9,OUTPUT); digitalWrite(9,HIGH);
Serial.println("Enter AT commands:");
mySerial.begin(38400);
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}```
[1]: https://i.stack.imgur.com/BhED7.jpg
In fact it is enough just to put the baud rate of the HC-05 also to 9600.
Related
I have been learning how to program in esp32 using arduino IDE.
I couldn't figure out how to use max98357a board with Esp32-DevKitC. I have tried "Audio.h" and "AudioTools.h" libraries but not is changed.
My first attempt was just testing voice output. My code is below:
#include "Arduino.h"
#include "WiFi.h"
#include "Audio.h"
// Digital I/O used
#define I2S_DOUT 26 // DIN connection
#define I2S_BCLK 27 // Bit clock
#define I2S_LRC 14 // Left Right Clock
Audio audio;
String ssid = "MYCROFT";
String password = "145678abc789";
void setup() {
Serial.begin(115200);
WiFi.disconnect();
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());
while (WiFi.status() != WL_CONNECTED) delay(1500);
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(21); // 0...21
// audio.connecttohost("http://www.wdr.de/wdrlive/media/einslive.m3u");
// audio.connecttohost("http://macslons-irish-pub-radio.com/media.asx");
// audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.aac"); // 128k aac
// audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3"); // 128k mp3
audio.connecttohost("http://vis.media-ice.musicradio.com/CapitalMP3"); // 128k mp3
// audio.connecttospeech("Wenn die Hunde schlafen, kann der Wolf gut Schafe stehlen.", "de");
// audio.connecttohost("http://media.ndr.de/download/podcasts/podcast4161/AU-20190404-0844-1700.mp3"); // podcast
}
void loop()
{
audio.loop();
}
It works as intended but when I try to add some commands to the loop function, It stops working.
I mean if I change the loop function as below, it stops connecting to the audio stream.
void loop()
{
delay(3000);
Serial.println("Hello");
audio.loop();
}
Is it possible to use max98357a with some additional codes apart from just simple audio.loop().
The delay(3000) instruction causes the microprocessor to do nothing but sit & wait for 3 seconds. Not even interrupts are serviced so audio is lost.
I've a simple led blinking example which I'm trying to run on a ESP32-SOLO-1 but as soon I flash it with the program I get the following message from the serial monitor:
E (102) cpu_start: Running on single core chip, but application is built with dual core support.
E (102) cpu_start: Please enable CONFIG_FREERTOS_UNICORE option in menuconfig.
abort() was called at PC 0x400829d2 on core 0
Here's the code
#include <Arduino.h>
#define LED_BUILTIN 2
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
And the platformio.ini config:
[env:esp-wrover-kit]
platform = espressif32
board = esp-wrover-kit
monitor_speed = 115200
framework = arduino
build_flags = -D CONFIG_FREERTOS_UNICORE
Adding the build flag CONFIG_FREERTOS_UNICORE has no effect.
I've been struggling for the past few days to get the Elechouse PN532 V3 module working with an ESP32 over I2C. The PN532 module itself works fine with a Raspberry Pi.
This is the circuit (not actually using SparkFun ESP32 board, just for reference)
And this is the code I'm trying to run
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
Wire.begin(18, 19);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void loop(void) {
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// Wait 1 second before continuing
delay(1000);
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}
And finally the serial output: Didn't find PN53X board
Any ideas what I'm doing wrong?
EDIT: libraries im using https://github.com/elechouse/PN532 and the ESP32 dev board is a Wemos Lolin32 Lite clone.
I don't have any of this hardware to verify this, but from 'PN532-PN532_HSU\NDEF\README.md'
For the Adafruit Shield using I2C
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
NfcAdapter nfc = NfcAdapter(pn532_i2c);
Try using the above in your code? I'd also suggest you review the PN532 I2C examples in more depth. The PN532 I2C library code defines a 'wakeup' function:
void PN532_I2C::wakeup()
{
delay(500); // wait for all ready to manipulate pn532
}
The comment makes me believe the device may require a significant delay (500ms) before it's ready to talk.
Best of luck.
sda and scl are 21 and 22
also make sure that you changed mode to I2C (those jumpers on PN532 module):
doc - page 3
I have this now working with an M5STACK grey core, the common issue was the I2C bus would lock up on a reset or re program. Use a spare I/O pin and connect to the PN532 reset pin, hold this low on boot, initialize I2C bus then drive reset high after 100mS problem solved no more bus conflicts.
I have a ATMega16 and have looped the Rx Tx (just connected the Rx to the Tx), to send and receive one char in a loop. But i only seems to be receiving 0x00 instead of the char i send.
I have the CPU configured to 1MHz.
But my thought is that since the Rx and Tx are just looped, it shouldn't matter what speed i set, since both are the same?
So basically, I'm trying to get a LED to flash at PORTC when receiving the correct char.
Here is the code:
#ifndef F_CPU
#define F_CPU 10000000
#endif
#define BAUD 9600
#define BAUDRATE ((F_CPU)/(BAUD*16)-1)
#include <avr/io.h>
#include <util/delay.h>
void uart_init(void){
UBRRH = (BAUDRATE>>8);
UBRRL = BAUDRATE;
UCSRB = (1<<TXEN) | (1<<RXEN);
UCSRC = (1<<URSEL) | (1<<UCSZ0) | (1<<UCSZ1);
}
void uart_transmit (unsigned char data){
while (!(UCSRA & (1<<UDRE)));
UDR = data;
}
unsigned char uart_recive(void){
while(!(UCSRA) & (1<<RXC));
return UDR;
}
int main(void)
{
uart_init();
unsigned char c;
PORTC = 0xff;
DDRC = 0xff;
while(1)
{
_delay_ms(200);
uart_transmit(0x2B);
c = uart_recive();
if(c==0x2B){
PORTC = PORTC ^ 0xff;
}
}
}
Any thoughts of what i am doing wrong?
The code seems right.
Thing you may have to check:
if your baudrate is the one you should have
if you try to send a char like 'p'; now you are sending a '+'
check your port configuration and see if it matches to your configuration
I think the last one is the problem.
You can try this code from ATMega manual:
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
After building your program, go to your port configuration and make sure it it set on 8 bits data format and 2 stop bits. Then test it on you microcontroller and see what happens. Please come back with the result.
Consider real baudrate accuracy. See e.g. http://www.wormfood.net/avrbaudcalc.php?postbitrate=9600&postclock=1, AVR provides 7.5% error for 9600baud # 1MHz clock, which is rather high error. Depend what you are sending and receiving. "Normally" you can see a garbage, if you receive permanently 0x00s it looks like another problem.
your F_CPU is set to 10MHz.
you sad that it is configured to 1Mhz.
Also check your Fuses if you really activated the crystal.
If you just use the internal oscillator: it has a relatively large error so that your UART timings may be broken (i never got problems using internal oscillator for debugging).
Another source of error may be your F_CPU definition. Mostly this Preprocessor constant is defined already (propably also wrong) in Makefile (or in IDE project settings) so your #define in Code has not affect since the #ifndef
PORTC pins(TDI,TMS,TCK,SDA) always high because these pins for JTAG and JTAG is enable by default. if you want to use PORTC in your application you have to Disable the JTAG by setting fuse bit. for atmega16 JTAGEN is fuse bit set it to 1(means unprogrammed). in case of fuse bit 0(means programmed) and 1(means unprogrammed) one more thing if you use more than 8MHz you have to set fuse bit otherwise your program will give unexpected or wrong result thanks.
If using Arduino, what would it do if I used code like this:
int status;
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
digitalWrite(13, status);
}
What would thiscode do? Would the LED turn on? Would it damage the chip? When compiling in the Arduino IDE, it said it was fine. There are other issues that the compiler won't catch, but what will they do? One other example is doing "digitalRead();" while it is set as an output.
Note: Using Arduino Uno SMD edition R2.
You will not damage the Arduino, but you cannot be sure about the output, since the value is not initialized. It holds whatever value the memory holds in its location (think of it as an unknown random value). Most probably though, it will be turned on, because digitalWrite sets the pin to high if you pass anything other than LOW (=0) to it. Look at Arduino's source code in wiring_digital.c:
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
Regarding your other questions:
Reading a pin value returns PINx register value, which is the physical state (high or low) of the pin, regardless of its mode (in or out).
In general, it is really difficult to damage Arduino, and in most cases you need to apply some high/negative voltage on some pins to damage it.