• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

unresponsive keypad on ESP32

Q&A Forum › Category: ESP32 › unresponsive keypad on ESP32
0 Vote Up Vote Down
Paul French asked 3 years ago

I have a process running where the kepad has become unresponsive.  It’s a hit and miss affair depending (I assume) on what part of the loop in running.
I’m using some DS18b20 temp sensors which I think may be causing a delay in the loop while they return the temp values.  I read that there is a method where you can sensors.setWaitForConversion(); and use a millis timer, such that the loop is not held up.  Maybe this might solve the problem but I don’t know how to correctly implement it as the examples do not operate with fixed hex addresses. 
Alternativly, I have read you can attach interrupts to the keypad, which sounds like  better solution, but I have not been able to find a detailed tutorial on how to implement this.  
Could someone please advise which route would be preferable and suggest an implementation. 
Many thanks, Paul

Question Tags: kepad
4 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Paul.
 
What’s the current method that you’re using to read the keypad?
Using interrupts seems a good idea. But, I think the main issue might be the time that it takes to get a reading from the sensor. So, I would go first with trying to read the sensor asynchronously.
 
There is this example in the library:

  • https://github.com/milesburton/Arduino-Temperature-Control-Library/blob/master/examples/WaitForConversion/WaitForConversion.ino

Instead of getting the temperature by index (sensors.getTempCByIndex(0)), you can get the temperature by address.
For example, imagine this is your address:

DeviceAddress sensor1 = { 0x28, 0xFF, 0x77, 0x62, 0x40, 0x17, 0x4, 0x31 };

Then use the following to get the readings by address:

sensors.getTempC(sensor1); 

 
I hope this helps.
Regards,
Sara

0 Vote Up Vote Down
Paul French answered 3 years ago

Hi Sara,
Thank you for your advice.  My code already defines the sensors adresses, however I have not been able to understand or implement the setwaitforconversion examples which use two separate start and stop millis() in a way I have not seen, not including a reset.
Can you provide an example user waitforconversion with set addresses?  Here is my code so far:-

 

uint8_t sensor1[8] = {0x28, 0x2B, 0xFA, 0x75, 0xD0, 0x01, 0x3C, 0xA2};
uint8_t sensor2[8] = { 0x28, 0x1D, 0x33, 0x75, 0xD0, 0x01, 0x3C, 0x2C};
uint8_t sensor3[8] = { 0x28, 0x0C, 0x14, 0x75, 0xD0, 0x01, 0x3C, 0xE9};// REPLACEMENT SENSOR 28 0C 14 75 D0 01 3C E9
unsigned long startTempSensorTimer = 0;
unsigned long stopTempSensorTimer = 0;

 
void setup()

//Start Temp Sensors DS18B20
  sensors.begin();
  if(sensors.isParasitePowerMode()) Serial.println(“DS18B20 in Parasitic power mode  – ON”);
  else Serial.println(“DS18B20 in Parasitic power mode  – OFF”);

 
void loop()

if(millis() – temptimer > 10000)
  {
  display_handle();
  startTempSensorTimer = millis();
  sensors.setWaitForConversion(false);  // makes it async
  sensors.requestTemperatures();
  ambientC = sensors.getTempC(sensor1); // Gets the values of the temperature
  waterC = sensors.getTempC(sensor2); // Gets the values of the temperature
  airoffC = sensors.getTempC(sensor3);
  sensors.setWaitForConversion(true);
  stopTempSensorTimer = millis();

  Serial.println(ambientC);
  Serial.println(waterC);
  Serial.println(airoffC);
  Serial.print(“float switch : “);
  Serial.println(floatSwitchStatus);
  Serial.print(“Master  switch : “);
  Serial.println(masterSwitchStatus);
  temptimer =millis();
  }

 

0 Vote Up Vote Down
Paul French answered 3 years ago

Hi Sara,
Thank you for your advice.  My code already defines the sensors adresses, however I have not been able to understand or implement the setwaitforconversion examples which use two separate start and stop millis() in a way I have not seen, not including a reset.
Can you provide an example user waitforconversion with set addresses?  Here is my code so far:-

 

uint8_t sensor1[8] = {0x28, 0x2B, 0xFA, 0x75, 0xD0, 0x01, 0x3C, 0xA2};
uint8_t sensor2[8] = { 0x28, 0x1D, 0x33, 0x75, 0xD0, 0x01, 0x3C, 0x2C};
uint8_t sensor3[8] = { 0x28, 0x0C, 0x14, 0x75, 0xD0, 0x01, 0x3C, 0xE9};// REPLACEMENT SENSOR 28 0C 14 75 D0 01 3C E9
unsigned long startTempSensorTimer = 0;
unsigned long stopTempSensorTimer = 0;

 
void setup()

//Start Temp Sensors DS18B20
  sensors.begin();
  if(sensors.isParasitePowerMode()) Serial.println(“DS18B20 in Parasitic power mode  – ON”);
  else Serial.println(“DS18B20 in Parasitic power mode  – OFF”);

 
void loop()

if(millis() – temptimer > 10000)
  {
  display_handle();
  startTempSensorTimer = millis();
  sensors.setWaitForConversion(false);  // makes it async
  sensors.requestTemperatures();
  ambientC = sensors.getTempC(sensor1); // Gets the values of the temperature
  waterC = sensors.getTempC(sensor2); // Gets the values of the temperature
  airoffC = sensors.getTempC(sensor3);
  sensors.setWaitForConversion(true);
  stopTempSensorTimer = millis();

  Serial.println(ambientC);
  Serial.println(waterC);
  Serial.println(airoffC);
  Serial.print(“float switch : “);
  Serial.println(floatSwitchStatus);
  Serial.print(“Master  switch : “);
  Serial.println(masterSwitchStatus);
  temptimer =millis();
  }

 

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi.
I think you just need to call sensors.setWaitForConversion(false);  before requesting the temperatures in a “regular” sketch.
I don’t think you need to use that millis(). It is used in the example just to check how long it takes to get readings.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.