Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By trackerj
#51842 For some unknown reasons the ESPBasic 3.0 Alpha 17 doesn't want to work with my local WIFI Router.
Anybody knows what are the changes regarding WIFI?

Now back to our PCF8574 story.

Below you can find a very simple example for testing and using the PCF8574 P0-P7 pins as output.

This is how is looking the hardware setup, ESP8266 nEXTEvo G2 Board + AN-1 extension board (it has also a full PCF8574 I/O expander port, what we needed for our test):

nEXTEVO_AN-1-PCF8574_1.jpg


Because couldn't find how to change the SDA/SCL pins I was forced to use the ESPBasic default allocated I2C pins, GPIO0 and GPIO2. Looks ugly, I know. I hope in the future it will be possible to choose your desired I2C pins as you wish and need:)

The software:

Code: Select alllet address=32 'PCF8574 I2C Address

button "1", [1]
button "2", [2]
button "3", [3]
button "4", [4]
button "5", [5]
button "6", [6]
button "7", [7]
button "8", [8]
button "OFF", [9]
wait

[9]
i2c.begin(address)
i2c.write(255)
i2c.end()
wait

[1]
i2c.begin(address)
i2c.write(254)
i2c.end()
wait

[2]
i2c.begin(address)
i2c.write(253)
i2c.end()
wait

[3]
i2c.begin(address)
i2c.write(251)
i2c.end()
wait

[4]
i2c.begin(address)
i2c.write(247)
i2c.end()
wait

[5]
i2c.begin(address)
i2c.write(239)
i2c.end()
wait

[6]
i2c.begin(address)
i2c.write(223)
i2c.end()
wait

[7]
i2c.begin(address)
i2c.write(191)
i2c.end()
wait

[8]
i2c.begin(address)
i2c.write(127)
i2c.end()
wait



The Web interface:

PCF8574_web_interface_1.jpg


Functional description: by pressing the "1"->"8" buttons you can activate the corresponding P0-P8 PCF8574 output pins. "OFF" = all off.

Please read carefully PCF8574 related articles and documents. SINK and SOURCE are not the same thing. Connect the LEDs for SINKING current!

And yes, was tested. Working OK. With LED's. Enjoy.

PS: they are some errors in the web console, maybe somebody want to take a look at.
You do not have the required permissions to view the files attached to this post.
User avatar
By forlotto
#51856 There is a slight problem with your code it only allows you to turn 1 on at a time. The other one turns off so what is needed is a routine that does the math to turn on the one that is on and the one that is off...


But the code does work rather quickly too I might add.

But this seems nearly same as the 595... There is a register that operates in the same manner it seems to control GPIO while the 595 seems a bit more latent it could be due to the math routine and bit banging ...

I will need to do further testing to see how to accomplish this as time permits. I would think I could even use the shift register code to do the trick but with the I2C addon more or less...
Going to have to do some testing.


But this was a lot more simplistic than I had figured.
User avatar
By forlotto
#51860 I have posted a fully working application on the front page all problems and issues solved works like a charm!

Figure out why it works just open up a calculator and you can see how the ports switch on and off.

If you want all on at start you will need to change code accordingly to reflect all 1's or the value of 255

If you want all off at first you will need set the value of 0 or all 0's with the first i2c routine .

This will sync the chip and set your status as all on or all off right away this prevents any button press from crashing them all on at once you must sync the chip first I believe this is where the problem lies and what he was talking about when he said syncing.

Enjoy

-forlotto
User avatar
By trackerj
#52094 Youtube video :



And the related Article: Mutually-exclusive switch driver Example