Page 1 of 1

Porting basic code to ESP32

Posted: Thu May 21, 2020 11:45 am
by TCC-ESP32
I have a small sketch I would like to port to the ESP32, but I can't get it to work.
The Arduino sketch and partially modified ESP32 sketch are here: https://github.com/Account-Git/Arduino-to-ESP32
Please, can anyone help?

Something so simple shouldn't be this difficult. :(

Re: Porting basic code to ESP32

Posted: Fri May 22, 2020 9:36 am
by rin67630
My glass ball needs a repair.

Please define "can't get it to work".
What did you do?
What did you expect?
What did you get instead?

Re: Porting basic code to ESP32

Posted: Fri May 22, 2020 11:07 am
by TCC-ESP32
Sorry, yes I should have made myself more clear.

First, I took my original, working, Arduino sketch (as shown on GitHub).
Then, I changed the pin numbers to match the GPIO pins on the ESP32. I also changed the baud rate for the Serial monitor.
And that's all I did.

I was hoping (expecting) to get the same results as I did with the Arduino.
i.e. When one of the inputs on the 74HC165 goes high the microcontroller receives a 1 on that bit, or a 0 if it goes low.

What I got instead was either one 0 instead of eight bits, or eight 1s, and sometimes just a load of rubbish (2 bits, 4bits, 5bits, etc).

It seems that the SPI setup is way off somewhere, but I am new to ESP32 and don't know how to set it up for this type of application despite it appearing very simple at the outset.

Re: Porting basic code to ESP32

Posted: Sat May 23, 2020 10:32 pm
by mrburnette
TCC-ESP32 wrote:
Thu May 21, 2020 11:45 am
...
Something so simple shouldn't be this difficult. :(
I have not examined your code, but generally the biggest porting issue from Arduino (UNO, Mega, Nano, Micro) and ESP32 is that AVR 8-bit uC has int defined as 16-bits and int on ESP32 is 32-bit.

Good luck.

Ray

Re: Porting basic code to ESP32

Posted: Mon May 25, 2020 8:52 am
by TCC-ESP32
Thanks, Ray

What is the "fix/workaround" for this?