Tally counter with SSD1306 OLED

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Tally counter with SSD1306 OLED

#1 Post by Trelsonowsky » 20 Jun 2023, 20:37

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!

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tally counter with SSD1306 OLED

#2 Post by TD-er » 20 Jun 2023, 21:25

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:

Code: Select all

on button#switch do
  // Increment the counter in variable #1
  let,1,[int#1]+1
endon
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]

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#3 Post by Trelsonowsky » 20 Jun 2023, 21:44

Hey, works perfectly thanks
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

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tally counter with SSD1306 OLED

#4 Post by TD-er » 20 Jun 2023, 21:47

Yep

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#5 Post by Ath » 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.

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
On the display you can use the predefined layout to display the counter value, using something like this:

Code: Select all

Counter value: [Level#GetLevel#D4]
Edit: Changed button value part to (default) 'state'.
Last edited by Ath on 20 Jun 2023, 23:03, edited 1 time in total.
/Ton (PayPal.me)

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#6 Post by Trelsonowsky » 20 Jun 2023, 21:57

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.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tally counter with SSD1306 OLED

#7 Post by TD-er » 20 Jun 2023, 22:03

Maybe even better to replace the flash chip for a 4M version.
That makes updating a lot easier

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#8 Post by Ath » 20 Jun 2023, 22:06

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)

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#9 Post by Trelsonowsky » 20 Jun 2023, 22:06

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.
Image

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tally counter with SSD1306 OLED

#10 Post by TD-er » 20 Jun 2023, 22:09

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

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#11 Post by Trelsonowsky » 20 Jun 2023, 22:33

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
Attachments
6fhWMUH.png
6fhWMUH.png (78.79 KiB) Viewed 2362 times
GPpXg3M.png
GPpXg3M.png (28.62 KiB) Viewed 2362 times
jbxu8fD.png
jbxu8fD.png (9.98 KiB) Viewed 2362 times
moAs1kB.png
moAs1kB.png (100.41 KiB) Viewed 2362 times
Last edited by Trelsonowsky on 20 Jun 2023, 22:59, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#12 Post by Ath » 20 Jun 2023, 22:51

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)

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#13 Post by Ath » 20 Jun 2023, 22:55

Trelsonowsky wrote: 20 Jun 2023, 22:33 https://imgur.com/a/ggRIfjH
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)

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#14 Post by Ath » 20 Jun 2023, 23:02

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)

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#15 Post by Trelsonowsky » 20 Jun 2023, 23:34

Yup, that was it. Thanks!

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#16 Post by Trelsonowsky » 21 Jun 2023, 00:03

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.

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
On the display you can use the predefined layout to display the counter value, using something like this:

Code: Select all

Counter value: [Level#GetLevel#D4]
Edit: Changed button value part to (default) 'state'.

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Tally counter with SSD1306 OLED

#17 Post by Ath » 21 Jun 2023, 08:43

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)

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#18 Post by Trelsonowsky » 22 Jun 2023, 20:08

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?
Attachments
Zrzut ekranu 2023-06-22 200202.png
Zrzut ekranu 2023-06-22 200202.png (40.28 KiB) Viewed 2267 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Tally counter with SSD1306 OLED

#19 Post by TD-er » 22 Jun 2023, 20:18

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.

Trelsonowsky
Normal user
Posts: 10
Joined: 25 Jul 2022, 18:21

Re: Tally counter with SSD1306 OLED

#20 Post by Trelsonowsky » 23 Jun 2023, 00:12

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

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests