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
ESP32 ports
-
- Posts: 23
- http://meble-kuchenne.info.pl
- Joined: Tue Nov 22, 2022 10:56 am
- Been thanked: 2 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: ESP32 ports
Hi
If you use a switch array you can simplify your project.
I modified your chart as an example.
Regards
If you use a switch array you can simplify your project.
I modified your chart as an example.
Regards
Re: ESP32 ports
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
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
Re: ESP32 ports
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
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
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: ESP32 ports
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.
Regards
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.
Regards
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: ESP32 ports
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
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