ESP32 ports

For general Flowcode discussion that does not belong in the other sections.
Post Reply
ctesla75
Posts: 23
http://meble-kuchenne.info.pl
Joined: Tue Nov 22, 2022 10:56 am
Been thanked: 2 times

ESP32 ports

Post by ctesla75 »

Hi All,
Just trying to use ports on esp32 im using 3 pins designated as input only , but donr know how to figure out the address in a switch command.
In AVR i was able to use the hex equivalent of binary e.g. 00000001 was 1 on the switch with portb as input , I cant find any documentation giving port addresses. I can get it to work if use single if commands set to portb.1 for example. but wanted to do with switch for a simpler flow chart.
I only get ther first button to work at pin39 with the value of 1
Thanks for reading
Attachments
BUTT.fcfx
(13 KiB) Downloaded 33 times

chipfryer27
Valued Contributor
Posts: 1165
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 415 times

Re: ESP32 ports

Post by chipfryer27 »

Hi

If you use a switch array you can simplify your project.

I modified your chart as an example.
BUTT_array.fcfx
(12.1 KiB) Downloaded 38 times
Regards

ctesla75
Posts: 23
Joined: Tue Nov 22, 2022 10:56 am
Been thanked: 2 times

Re: ESP32 ports

Post by ctesla75 »

Hi
Thanks for the reply, i cannot get your example to work in simulation. i dont know if it is a faulty download although i have downloaded it twice
.First time it said it was made on a newer version, so i upgraded and tried again. Flowcode states. Unknown or missing component: switch_array_push1:ReadAll.
P.S. I have a licensed version of flowcode but with only the display add on sofar

ctesla75
Posts: 23
Joined: Tue Nov 22, 2022 10:56 am
Been thanked: 2 times

Re: ESP32 ports

Post by ctesla75 »

Hi
I have realised the error due to me not having the license for the switch, is there a way to know the port codes in the switch command

chipfryer27
Valued Contributor
Posts: 1165
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 415 times

Re: ESP32 ports

Post by chipfryer27 »

Hi

Well one alternative is to read the whole port and switch based on result. Mask unused or ports of no interest.

I added in a delay of 800mS which will allow your display to update before being cleared again. You will need to press buttons for at least this time to ensure they get read.

Update FC regularly, Help>Library Updates to make sure you are using latest components and in Global Options make sure "Check for Core Updates" is ticked.
BUTT_Input.fcfx
(12.21 KiB) Downloaded 31 times
Regards

ctesla75
Posts: 23
Joined: Tue Nov 22, 2022 10:56 am
Been thanked: 2 times

Re: ESP32 ports

Post by ctesla75 »

Thanks for your help can i ask where the values of 4 and 128 came from in switch

chipfryer27
Valued Contributor
Posts: 1165
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 415 times

Re: ESP32 ports

Post by chipfryer27 »

Hi

When you simulate you will see in the Simulation Debugger that you can slow down the speed. If you set it at say 2 or 5Hz you will be able to see things as they happen. If you then select "Input" as an expression you will see it's value change as you progress through the program (I might have left a couple of unused variables there, if so just delete).

If you look at each button's properties it will show the connection (e.g. $pin34 for button 1). If you then click on the "connection" a chip diagram appears and you can select whatever pin you wish. You will also see a box "Use Chip Reference" and if ticked it will show you Port B / 2. Your buttons are Port B 2/3/7.

Port B 2/3/7 refers to Port B bits 2, 3 and 7

We count bits starting at 0 ending at 7 (for eight bit ports). Bit 2 has a value of 4, bit 3 has a value of 8 and bit 7 a value of 128.

7 - 6 - 5 - 4 - 3 - 2 - 1 - 0 (bits)

128 - 64 - 32 - 16 - 8 - 4 - 2 - 1 (decimal)

When you read the masked port, you will return a 0 if no button is pushed or 4 / 8 /128 which corresponds to the decimal value of the "bit" your button is connected to. If you connected to bit 5 you would return 32 etc.

Hope this helps.

Regards

ctesla75
Posts: 23
Joined: Tue Nov 22, 2022 10:56 am
Been thanked: 2 times

Re: ESP32 ports

Post by ctesla75 »

Thankyou for the help that explains it perfectly

Post Reply