DS1307 doesn't run at all [closed] - arduino

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 days ago.
Improve this question
Okay, so i have two DS1307 in front of me and they differ in hardware. I have no clue about electronics, so I don't know what that element is, but here's a photo:
I run them with an ESP8266.
One of them is working correctly with the code provided below, the other isn't. I have no idea why. Here's the code:
#define SCL_PIN 5 // D1 PIN
#define SDA_PIN 4 // D2 PIN
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600);
Wire.begin(SDA_PIN, SCL_PIN);
rtc.begin(); // <- fails here depending on type of DS1307
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)) + TimeSpan(0,0,0,20));
}
void loop() {
delay(5000);
DateTime dt = rtc.now();
int second = dt.second();
int minute = dt.minute();
int hour = dt.hour();
int day = dt.day();
int month = dt.month();
int year = dt.year();
Serial.print("-> it's ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(" # ");
Serial.print(day);
Serial.print(".");
Serial.print(month);
Serial.print(".");
Serial.println(year);
}
On the DS1307 on the right side of the photo, the code works fine, rtc is initialized and shows the correct time from my OS. On the left side it won't initialize and shows the debugging string as:
20:154 # 148.3.2000
Without the RTCLib.h, if I only read with the Wire object at 0x68, I get the date 165.165.165
Any ideas on how to resolve the problem? Or what the problem is at all?
I tried:
another DS1307 of the same kind, it's always this component that differs that makes the code run or not.
get datetime from memory at 0x68 with Wire object
only run DS1307 alone with ESP8266

Related

Switch state not changing according to physical changes nodeMCU float switches

I am using float switches(3 Nos) as depicted below and a NodeMCU esp8266,
all three switches have been defined in the same way(input_pullup)
2 of these switches change state as the switch movement commands but one of these switches are not changing state and are stuck in LOW forever
please find the pin and code attached below with a picture of the switch in open and closed state.
uint8_t level1=D0; //switch with issue // have also tried with D8 as only these two pins are free
uint8_t level2=D1; //switch working fine
uint8_t level3=D3; //switch working fine
pinMode(level1,INPUT_PULLUP);
pinMode(level2,INPUT_PULLUP);
pinMode(level3,INPUT_PULLUP);
}
int currlevel=0;
void loop() {
int level1Sensor=digitalRead(level1);
int level2Sensor=digitalRead(level2);
int level3Sensor=digitalRead(level3);
Serial.println(level1Sensor);
Serial.println(level2Sensor);
Serial.println(level3Sensor);
CLOSED STATE PICTURE
OPEN STATE PICTURE
NOTE: i am also using an nrf24L01 for communication in the same nodeMCU but the pins used for these switches are not overlapping.
As mentioned in the link #Juraj posted, D0 (GPIO16) does NOT have an internal pull-up. It has an internal pull-down. Use a different pin.

RCSwitch library seemingly not working for 433 Hz receiver on ESP32 NodeMCU

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)

Having trouble programming wifi on esp8266

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.

Protocol for writing data to 16x2 LCD via I2C

I am new to electronics and has completed a tutorial on how to operate a 16x2 Character LCD via I2C in Arduino using liquidCrystal_I2C. Everything works fine but I have a question about the low level interaction between the I2C and the LCD. Looking at the library's source code, I notice that when writing a 4 bits nibble (LiquidCrystal_I2C::write4bits), the code writes the nibble to the I2C expander first
(LiquidCrystal_I2C::expanderWrite), and then writes again when pulsing the Enable bit. Why is the first expanderWrite necessary? Why can't write4bits just call pulseEnable (with the blacklight bit set)?
I am sure there is a reason as I checked other library like RPLCD and see a similar pattern. Can anyone enlighten me? Thank you.
From the datasheet I found the LCD requires specific timing in the communication protocol.
On the rising edge of the enable line the Register Select and Read/Write lines must have already settled for tsu1 (100ns). On the falling edge of the enable line the data must have already settled for tsu2 (60ns). By writing _data they are also writing the RS and R/W lines as they are the lower nibble of _data.
This article covers the topic very thoroughly.
//**** From LiquidCrystal_I2C.h
// flags for backlight control
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
#define En B00000100 // Enable bit
#define Rw B00000010 // Read/Write bit
#define Rs B00000001 // Register select bit
// ^--------Backlight bit defined above
// ^^^^---------Data bits
//**** From LiquidCrystal_I2C.cpp
void LiquidCrystal_I2C::write4bits(uint8_t value) {
expanderWrite(value);
pulseEnable(value);
}
void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
Wire.beginTransmission(_addr);
Wire.write((int)(_data) | _backlightval);
Wire.endTransmission();
}
void LiquidCrystal_I2C::pulseEnable(uint8_t _data){
expanderWrite(_data | En); // En high
delayMicroseconds(1); // enable pulse must be >450ns
expanderWrite(_data & ~En); // En low
delayMicroseconds(50); // commands need > 37us to settle
}

I2C MCP3221 12 bit ADC reading 0 at any voltage

I've hooked up an MCP3221 to a Teensy 3.1 on the I2C bus and connect it to Vref(3.3V), just to check if it's working. However it's reading 0, even when I hook it up to a different voltage. Is my code faulty or should I just get a new device?
#include <MCP3221.h>
#include <Wire.h>
#include "SoftwareSerial.h"
#define ADDRESS 0x4D // 7 bits address is 0x4D, 8 bits is 0x9B
MCP3221 adc(155,0x3);
void setup() {
Serial.begin(9600);
Serial.println("First");
Wire.begin(); //connects I2C
}
void loop() {
Serial.println(adc.readI2CADC());
delay(10);
}
There is a list of device addresses in the Microchip data sheet DS21732C on the page 20.
Depends on the marking code on your chip.
You are not using the right address. You declare the constant but never use it. The adc declaration should be like this
MCP3221 adc(ADDRESS, 0x3);
Why? Doing a little search, I found out that instead of 8 bits address (155 in decimal or 0x9B in hexadecimal), you have to use 7 bits address, 0x4D in this case. You can see that in this example, too. I think you should have this example in the Arduino IDE, in File > Examples > MCP3221.
Looking at the example, seems like the second argument you passed to the adc can be wrong, too, but I'm not sure about this. Try a greater value if you see you always measure the same.

Resources