Power DHT11 with pin out Wemos D1 R1 - sensors

I am trying to run a DHT11 sensor from my Wemos D1 R1. I have the ground connected to ground and the sensor connected to D2 pin with a resister between sensor and power line. I have tried to connect the power to the D3 pin and setting the pinMode(D3,OUTPUT);and digitalWrite(D3,HIGH);, but the sensor isn't recognized. If I connect the power to the 3.3v output pin on the Wemos it works fine. I am plugging the Wemos into my computer's USB. Can someone tell my why the Wemos isn't being powered up by the D3 pin. Do I need to connect 9v to the Wemos instead of the computer power? Not a big deal but would be nice to understand why and to hook it up to another power pin.
This is my code that activates the pins and turns on the power to the D3 pin.
#include <DHTesp.h>
DHTesp dht;
pinMode(D3,OUTPUT);//make pin D3 a power outlet for 3.3v
void setup() {
Serial.begin(115200);
dht.setup(D2, DHTesp::DHT11);
digitalWrite(D3,HIGH);//make pin D3 hot
}
void loop() {
delay(8000);
float t = dht.getTemperature();
float f = (t*1.8) + 32;
if (isnan(t))
{
Serial.println("Failed to read from DHT2 sensor!"); **//when the sensor is powered by pin D3 this shows up but when powered by 3.3v it does get the sensor amount**
return;
}
Serial.print(", \"maintemp\": ");
Serial.print(f);
Serial.print("}\n");
delay(2000);
}

Are you sure you can do dht.setup(...) before you have power on the DHT11? I would guess that it need power first and then setup. You might even need to have a pause before.
Also; make sure you compile for the right board or else D3 might not relate to D3 on the board.

The following code tries to first initialize the DHT sensor but only powers it up afterwards. That won't work as the initialization code already tries to communicate with the sensor, which has no power:
dht.setup(D2, DHTesp::DHT11);
digitalWrite(D3,HIGH);//make pin D3 hot
So instead write:
digitalWrite(D3,HIGH); // power up the sensor
delay(500); // allow some time to become ready
dht.setup(D2, DHTesp::DHT11); // initialiye the sensor
BTW: Is the pinMode command outside the setup function? Does it compile like this?

DHT11 pinouts as follow:
1 VCC -> outer power is better, operates from 3.5 to 5.5V
2 DATA -> WEMOS D2...D7
3 NC
4 GND -> GND
if connect to D2 then write your code as follow:
dht.setup(D2, DHTesp::DHT11);

Related

Crackly audio when sending audio via bluetooth->arduino->DAC->3.5mm breakout board->headphones. Do not know the cause

I wrote a mix of python code and arduino code to make this work. I am sending an array of numbers (audio) to the HC-05 bluetooth module/arduino uno (these are both set to communicate via serial at 115200 baud, at least that is what I set for both (Serial.begin(x) for arduino and through AT commands for HC-05) ranging from 0-4095 as strings from python via bluetooth (bluetoothsocket(RFCOMM)).They are received character by character in the arduino and read into an array which will convert the char array into the single original unsigned int. Up to there I can confirm that chars were received and definitely constructed into integers. Those integer values are passed into a 12-bit DAC via I2C (SDA (A4)/SLC (A5) pins on the arduino. On the webpage (https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial/using-with-arduino) it says that to increase the speed for the transmission you write this "TWBR = 12; // 400 khz" in the arduino script, I'm guessing. Otherwise the DAC will transmit at 100kHz; so I set the transmission speed to 400kHz for the DAC. When I connect the DAC output to the 3.5mm breakout/earbuds I only hear crackling, absolutely no "sound". The earbuds work just fine on my laptop, so the problem is something else. The DAC definitely outputs a voltage (triangle wave file from webpage works) and I tried two 3.5mm breakout boards (maybe shoddy soldering work?). Does anyone have an idea of what the issue could be or steps I could take to find what the error is? My guess is that somewhere the transmission rates/bit transfers do not line up, but that is what I'm trying to find out by asking.
On the python side, the code more or less looks like this:
*initializing socket, setting to non-blocking socket,etc..
for i in range((1000)): #just to test, the file Id like to send is maybe 300,000 strings
HC05_socket.send(soundchars[i])
And this is the arduino code:
#define ledPinr 4
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;
int wait =10000; //
void setup() {
// put your setup code here, to run once:
pinMode(ledPinr, OUTPUT);
digitalWrite(ledPinr, LOW);
Serial.begin(115200);
dac.begin(0x62);
TWBR = 12; // 400 khz done in library
Serial.setTimeout(wait); // for now
}
void loop() {
// Read serial input:
char val[4]; // length 4 for 12-bit resolution
if (Serial.available()){
digitalWrite(ledPinr, LOW);
Serial.readBytesUntil(',', val, 4);
int num = atol(val);
dac.setVoltage(num, false);
Serial.print(num);
}
if (Serial.available()==0){
digitalWrite(ledPinr, HIGH);
}
}
Note: ignore the LED code lines, that is just to have an idea of the data flow as I run the program.
There are many reasons that can lead to crackling audio especially in these kind of setups (as I'm sure you're aware).
A couple of things :
Although in the example you link it says to write TWBR = 12, if you look at the source code of the library it checks for the #define TWBR macro. So I would change your code to have #define TWBR 12 before your setup() function.
How often are you receiving the bluetooth data? It doesn't look like you are handling what's happening when you receive no data the DAC will just freeze on whatever value you wrote last
Make sure you are calling the right address -> you didn't mention if A0 is connected to VCC in your setup.
First, be sure to call begin(addr) where addr is the i2c address
(default is 0x62, if A0 is connected to VCC its 0x63)
Side notes:
In my experience people try to avoid using atol(). If you look at adafruit's examples they use pgm_read_word() instead.
12 Bit isn't very high audio resolution for audio playback so most audio will be distorted (other than very basic digital sounds)
Make sure the audio you're sending from Python is playable (I don't know what your test case is)
In the end it could always be the soldering but I think it will be unlikely.

Using Arduino Leonardo with HC-05 to send string to PC with HC-05

I am currently working on making the computer and the arduino board communicate with bluetooth module hc-05 connect on each.
However, my program can show the string, which is counting the seconds, on the serial monitor of the arduino IDE. But when I unplugged the USB cable providing power to the arduino board and replace it with the 9V battery, the Tx LED on the board keeps turning on and when I open the tera term tuning to the correct baud rate, nothing shows up.
Here is the arduino code I used copied from here.
int counter =0;
void setup() {
Serial.begin(9600);
delay(50);
}
void loop() {
counter++;
Serial.print("Arduino counter: ");
Serial.println(counter);
delay(500); // wait half a sec
}
I am really new to Arduino, only started for a week. I really sincerely hope that you guys can provide help. Thanks.
You should use Serial1 but not Serial for bluetooth on Leonardo. Serial is for the USB only on Leonardo.

Characters not properly displayed in serial monitor in arduino

Can anyone tell me why the characters are not getting printed properly in the serial monitor of Arduino? I am pasting the arduino code.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);
int bluetoothTx = 15;
int bluetoothRx = 14;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
int incomingByte;
void setup() {
pinMode(53, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
delay(320); // IMPORTANT DELAY! (Minimum ~276ms)
bluetooth.print("$$$"); // Enter command mode
delay(15); // IMPORTANT DELAY! (Minimum ~10ms)
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
bluetooth.begin(9600); // Start bluetooth serial at 9600
lcd.print("done setup");
}
void loop()
{
lcd.clear();
Serial.print("in loop");
//Read from bluetooth and write to usb serial
if(bluetooth.available()) {
Serial.print("BT here");
char toSend = (char)bluetooth.read();
Serial.print(toSend);
lcd.print(toSend);
delay(3000);
}delay(3000);
}
Can anyone take a look into it. It does not print the character that I provide instead it prints something else like 'y' with 2 dots on top etc. Tried almost all the available solution.
Your issues could be one of a couple things. First and easiest to check is COMMON GROUND. Did you connect just the RX and TX pins or also the GND (ground) pin? Make sure that the ground from the BT mate is connected to the Arduino ground.
If you have done that, then your issue is with the baud rate. I'm pretty sure that SoftwareSerial can't read at baud rates beyond 57600. Arduino.cc docs say it can read at 115200, but other places say it will only write up to 115200.
To test this, you will either need to change the settings for this on the Bluetooth Mate or use a Mega or Leonardo which will have a hardware serial port (other than the one used for USB) which you should be able to configure for 115200.
If you try it with hardware serial either on a Mega or just using an FTDI or something and the messages still look garbled then perhaps the bluetooth mate is not actually configured to talk at 115200 as it claims. Trying reading the docs or testing with other baud rates.
Check whether error is present due to one of the following reasons:-
1) You haven't given any command to exit from the data mode. After setting the baudrate to 9600, you are directly switching to loop. You haven't given the command to exit the command mode.
2) I too had the same problem when I was using RN171 Wi-Fi module. The cause of the problem in my case was because I was sending data to Wi-Fi module in integer format instead of uint_8. While reading from the Wi-Fi module serially with arduino mega, I was reading it in the format of characters.
You have to remember that int is actually signed 16 bit integer. So while sending data to your Bluetooth module you have to send it as uint_8 or ASCII values of the characters that you want to send. You should also read it in the same format as you sent it.
3) If these are not the error then as calumb said, there can be error in setting the bluetooth module in command mode. You haven't checked for reply from bluetooth module whether it is really in command mode or not. You must read an CMD reply from bluetooth module and at the end of every command a reply of ack to conform that its really done what you want it to do.
This may be because of Bluetooth parsing data simultaneously. when sending two different data at the same time this may happens. try to control your data flow.

Can I use UART on MSP-EXP430F5529LP from Energia in order to communicate on pins p3.3 and p3.4 (rx and tx respectively)?

Can I use UART on MSP-EXP430F5529LP from Energia in order to communicate on pins p3.3 and p3.4 (rx and tx respectively)?
I already use UART in order to communicate with my PC via USB. To do so, I use Serial.println() and such. Now that one UART is taken, how do I configure and use second UART to go to these pins? Or would it be better to rewire my Bluetooth chip (BlueGiga wt32) to some other pins?
Configuration aside, Serial does not seem to allow for multiple UARTs. How does it know which UART to print to?
For some reason, I could not find any manual on interacting with wt32 from Energia, or on interacting with multiple UARTs on Energia.
Edit: found this link: http://forum.43oh.com/topic/3942-stellaris-lm4f120-multiple-uart-problem/
only, incidentally, they say it does not work. Still, a lead.. but it is my understanding that I still have to configure UART on those two pins, if at all possible.
Edit2 Found MultiSerial example in Energia:
/*
Multple serial test
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
The circuit:
* Any serial device attached to Serial port 1
* Serial monitor open on Serial port 0:
created 30 Dec. 2008
by Tom Igoe
This example code is in the public domain.
*/
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
}
Now, this may sound like a really noob question, but where is my Serial1?? Is it somewhere on my pinout? The corresponding page in Energia manual is just a stub.
Now, this link: http://energia.nu/Tutorial_SerialCallResponse.html has a pinout according to which P1.1 is TXD, P1.2 is RXSD, which is something that I have not seen documented elsewhere. I suspect that it is assigned in this particular example, only I don't see the assignment in the code; also, I suspect that this is the backchannel, unless the switch is turned. Confused!
Edit3: found SoftwareSerial example that turns pins of your choice into a RX and TX. So at least I probably have a software solution. Of course, I'd prefer hardware. The manual for the launchboard says the hardware supports up to 4 serial ports, but how? Where are the pins?
Sorry I keep adding to this. I'll tidy it out when there is a solution.
If you dont need those uart pins to talk to the host you can remove the jumpers on that board that connect rxd and txd and then connect those to your bluetooth module.
Serial.begin(); works for backchannel UART pins(Txd,Rxd between target ic & debugger ic marked in white squares in below image)
http://energia.nu/wordpress/wp-content/uploads/2015/03/2016-06-09-LaunchPads-MSP432-2.0-%E2%80%94-Pins-Maps.jpg
Serial1.begin(); works for P3_2 & P3_3

Software Serial.h Library not working

I created a WP8 App. It connects to the Bluetooth and detected it.and the Bluetooth module connected as well. But the data are not coming from the Arduino to the phone :(
error code
if(btSerial.available()) {
Serial.println(distance);
btSerial.write(distance);
}
else {
Serial.println("error"); -> always prints this
}
in the code always the error part is printing in the serial monitor. I have attached the pins in the Bluetooth device to below pins.
RXD - 11,
TXD - 10,
GND - GND,
VCC - 5v,
Please help me why is btSerial.available() is not firing ?
You have the logic backwards. available() tests whether the Arduino has data in its receive buffer. It does not test if the connection is ready. So the overall pattern of a serial program
if(someserial.available()) {
someserial.read... loop to get input
print stuff received
}
To write, just write.
//no if's just go
someserial.write("my output")
You do not need to wait. With the two wire serial connection, you have no flow control. In other words, there is no signalling between arduino and bluetooth transceiver about ready or other status. Because the baud rate of the bluetooth link exceeds the baud rate of the arduino serial link, you can't really overflow the bluetooth transmit stream.
The bluetooth aspect of negotiating the connection is meant to be transparent to the Arduino. In other words, your program is the same as if you where using a hardware serial port. If for some reason, you need details into the connection, there are special byte sequences that allow communication with the bluetooth hardware.

Resources