Tally counter with SSD1306 OLED
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Tally counter with SSD1306 OLED
Hello,
Is it possible to make a simple counter that would add "1" to a value displayed on SSD1306 display, every time a button is pressed?
I'm pretty clueless if it comes to rules. I have both display and a button setup correctly but I can't get it to work together.
What would be perfect is if the OLED would contantly display "000000" and just add 1 when button is pressed. You can think of it as a stattrak from csgo(because thats exactly what im trying to do).
Also is it possible for it to retain the counter when theres no power?
Cheers!
Is it possible to make a simple counter that would add "1" to a value displayed on SSD1306 display, every time a button is pressed?
I'm pretty clueless if it comes to rules. I have both display and a button setup correctly but I can't get it to work together.
What would be perfect is if the OLED would contantly display "000000" and just add 1 when button is pressed. You can think of it as a stattrak from csgo(because thats exactly what im trying to do).
Also is it possible for it to retain the counter when theres no power?
Cheers!
Re: Tally counter with SSD1306 OLED
Let's assume you have a switch task calles "button" with taskvalue called "switch"
You should set the Switch button type to Push Button Active Low and have the de-bounce set to make sure you only see a single action when pressing the button.
See: https://espeasy.readthedocs.io/en/lates ... tch#switch
This will then also generate an event when the button is pressed, like this "button#switch=1"
So in the rules you act on the event like this:
In the task for your display you simply put [int#1] to show the integer value.
You can also format the value, like adding leading zeroes.
See: https://espeasy.readthedocs.io/en/lates ... red-values
To format the value to 4 digits, you can use [int#1#D4]
You should set the Switch button type to Push Button Active Low and have the de-bounce set to make sure you only see a single action when pressing the button.
See: https://espeasy.readthedocs.io/en/lates ... tch#switch
This will then also generate an event when the button is pressed, like this "button#switch=1"
So in the rules you act on the event like this:
Code: Select all
on button#switch do
// Increment the counter in variable #1
let,1,[int#1]+1
endon
You can also format the value, like adding leading zeroes.
See: https://espeasy.readthedocs.io/en/lates ... red-values
To format the value to 4 digits, you can use [int#1#D4]
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Hey, works perfectly thanks
And for a "negative button" this would work right?
And for a "negative button" this would work right?
Code: Select all
on button2#switch do
// Reduce the counter in variable #1
let,1,[int#1]-1
endon
Re: Tally counter with SSD1306 OLED
To store the counter value you can use a Level Control task. That has an option to save the value, but can incorporate some delay, to avoid wearing out the Flash storage by saving too often. The GPIO option can be ignored, and the Set Level is the value that will be displayed, so can get an initial value. Assuming you don't plan to switch off the device often, the Auto-save interval can be set to something like 30 minutes.
On the display you can use the predefined layout to display the counter value, using something like this:
Edit: Changed button value part to (default) 'state'.
Code: Select all
on button#state do
let,1,[Level#GetLevel]+1 // Increment last counter value
config,task,level,SetLevel,[int#1] // Store new value, will be auto-saved
endon
on button2#state do
let,1,[Level#GetLevel]-1 // Decrement last counter value
config,task,level,SetLevel,[int#1] // Store new value, will be auto-saved
endon
Code: Select all
Counter value: [Level#GetLevel#D4]
Last edited by Ath on 20 Jun 2023, 23:03, edited 1 time in total.
/Ton (PayPal.me)
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
I unfortunately don't have a Level Controll option as a device. Im using ESP01 and my options are kinda limited( im using ESP_Easy_mega_20220616_custom_ESP8266_1M). I don't mind wearing out flash, these modules are dirt cheap so I can just get a new one.
Re: Tally counter with SSD1306 OLED
Maybe even better to replace the flash chip for a 4M version.
That makes updating a lot easier
That makes updating a lot easier
Re: Tally counter with SSD1306 OLED
We don't have another plugin that can easily store a value for you, but more recent builds do have a normal build for 1MB ESP8266 units, you can download f.e. the latest merge build from Github Actions.
/Ton (PayPal.me)
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Can that be done with dummy device?
My options are kinda limited
I dont think soldering a 4M chip is a viable option since it would require microsoldering and I dont have equipment for that.
My options are kinda limited
I dont think soldering a 4M chip is a viable option since it would require microsoldering and I dont have equipment for that.
Re: Tally counter with SSD1306 OLED
The dummy tasks only keep the values during crash/reboot.
Not on a power loss.
And those 8 pin flash chips are actually relatively simple to solder, even with a rather crude soldering iron.
Edit:
See: https://www.electronics-lab.com/upgrade ... h-4mb-one/
The video (as blocked when opening embedded on that page) https://www.youtube.com/watch?v=7Q6ABad7U6o
Not on a power loss.
And those 8 pin flash chips are actually relatively simple to solder, even with a rather crude soldering iron.
Edit:
See: https://www.electronics-lab.com/upgrade ... h-4mb-one/
The video (as blocked when opening embedded on that page) https://www.youtube.com/watch?v=7Q6ABad7U6o
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Ok as it turns out, "normal" version contains both Display and Level Control modules. I tried a counter with Level Control but it's not working. Pressing the button changes it's state from 0 to 1 and vice versa, and so is the level control, just the oposite value.
https://imgur.com/a/ggRIfjH
https://imgur.com/a/ggRIfjH
- Attachments
-
- 6fhWMUH.png (78.79 KiB) Viewed 3039 times
-
- GPpXg3M.png (28.62 KiB) Viewed 3039 times
-
- jbxu8fD.png (9.98 KiB) Viewed 3039 times
-
- moAs1kB.png (100.41 KiB) Viewed 3039 times
Last edited by Trelsonowsky on 20 Jun 2023, 22:59, edited 1 time in total.
Re: Tally counter with SSD1306 OLED
You're not using the output, but the, not visible on the Devices page, GetLevel value. If you open the task settings you'll see the updated Set level value (not updated when the page is open, but loaded when opening the page)
/Ton (PayPal.me)
Re: Tally counter with SSD1306 OLED
Hm, please attach screenshots to the forum (Attachments tab below the editing area), as those external services tend to 'lose' your images after a couple of months, making the post effectively useless.
/Ton (PayPal.me)
Re: Tally counter with SSD1306 OLED
Your button has the (default) Values name State, but the rules use switch. Best would be to change the rules to use State (not case-sensitive, btw) instead of switch. At least it has to match with what's used on your tasks
/Ton (PayPal.me)
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Yup, that was it. Thanks!
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Tried to do it myself BUT there is no Autosave interval. What do? :'(
Ath wrote: ↑20 Jun 2023, 21:47 To store the counter value you can use a Level Control task. That has an option to save the value, but can incorporate some delay, to avoid wearing out the Flash storage by saving too often. The GPIO option can be ignored, and the Set Level is the value that will be displayed, so can get an initial value. Assuming you don't plan to switch off the device often, the Auto-save interval can be set to something like 30 minutes.On the display you can use the predefined layout to display the counter value, using something like this:Code: Select all
on button#state do let,1,[Level#GetLevel]+1 // Increment last counter value config,task,level,SetLevel,[int#1] // Store new value, will be auto-saved endon on button2#state do let,1,[Level#GetLevel]-1 // Decrement last counter value config,task,level,SetLevel,[int#1] // Store new value, will be auto-saved endon
Edit: Changed button value part to (default) 'state'.Code: Select all
Counter value: [Level#GetLevel#D4]
Re: Tally counter with SSD1306 OLED
If you upgrade to a more recent release of ESPEasy, that should have the Auto-save interval available, as it has been introduced not that long ago. You can download the last mega build from here: https://github.com/letscontrolit/ESPEas ... 5265687433 (You will need a free Github account to be able to download files from there).
/Ton (PayPal.me)
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
It's always uphill for me. It works perfectly when powered via usb programator, but whenever I power it from a regulated 9V battery, the whole thing freezes after one button press(the number increases once though) and voltage regulator gets very hot.
Do you think you could help me? Or should I maybe create a separate post?
Do you think you could help me? Or should I maybe create a separate post?
- Attachments
-
- Zrzut ekranu 2023-06-22 200202.png (40.28 KiB) Viewed 2944 times
Re: Tally counter with SSD1306 OLED
A linear regulator is a really bad idea for such a large voltage drop.
Linear voltage regulator means the regulator acts as sort of resistor to make sure the output voltage remains the fixed.
However the current on the input and the output is the same.
So 9V input, 3.3V output means there is 5.7V drop between input and output.
Let's assume 150 mA current, then the voltage regulator alone consumes 0.855 Watt.
Since the current is the same, the ratio is 3.3 : 5.7 when considering the power consumption of the ESP and the voltage regulator.
Thus the voltage regulator takes nearly 2x as much power as the ESP (& sensors/display)
Better use some DC/DC converter.
Still I think it is a bad idea trying to power this from a 9V battery as you are wasting quite a lot of energy, those batteries don't have a lot of energy to begin with and a lot of those voltage regulators also take quite some energy when the device on the output of those regulators hardly uses anything.
Linear voltage regulator means the regulator acts as sort of resistor to make sure the output voltage remains the fixed.
However the current on the input and the output is the same.
So 9V input, 3.3V output means there is 5.7V drop between input and output.
Let's assume 150 mA current, then the voltage regulator alone consumes 0.855 Watt.
Since the current is the same, the ratio is 3.3 : 5.7 when considering the power consumption of the ESP and the voltage regulator.
Thus the voltage regulator takes nearly 2x as much power as the ESP (& sensors/display)
Better use some DC/DC converter.
Still I think it is a bad idea trying to power this from a 9V battery as you are wasting quite a lot of energy, those batteries don't have a lot of energy to begin with and a lot of those voltage regulators also take quite some energy when the device on the output of those regulators hardly uses anything.
-
- Normal user
- Posts: 10
- Joined: 25 Jul 2022, 18:21
Re: Tally counter with SSD1306 OLED
Well the problem is, the same thing happens with a dcdc step down converter. Also I don't have too many other options to get something of this size with protection and 3 volts. LiPo is problematic since most bms for them, cutoff the voltage at 2.5 which might be ok for a 18650 battery, but isn't for a typical lipo pack. And 18650 are way too big for my project anyways
Who is online
Users browsing this forum: No registered users and 2 guests