-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wokwi support #35
Comments
I would like to have all the hd44780 i/o classes working in woki. There are half a dozen or so different i2c backpacks that use different wiring between the PCF8574 and the LCD, and then there are 3 different backlight circuits. I don't know how the emulations work and how they interact with each other when connected, I'm guessing you will need some information from me about this as there is no place where these interactions are actually documented. i.e. you are not going to find this in the hd44780 datasheet and there is no real place to look to see the effect of using a transistor base pin as in input to a PCF8574 port pin with its weak pullup. What do you need from me to get started? |
It is more than ioread() But PCF8574 reads still needs to work since the library does probing during initialization to figure out the h/w design for the proper low level initialization/configuration. Direct probing of the backpack h/w is done through the i/o expander chip (which can be PCF8574 or MCP23008) in ioinit() by calling IdentifyIOexp() to determine the type of io expander chip (PCF8574 vs MCP2008) and then and autocfg8574() to determine the pin mappings and backlight control active level for the PCF8574 based backpacks. |
There are comments in code for the IdentifyIOexp() and autocfg8574() where I tried to explain what the code is looking for. |
Thank you. This was really helpful! Luckily, the code is well commented, so I was able to quickly figure out what the simulator needs to do - it boils down to returning 0x00 any time after 0x00 is written (that matches the PCF8574 detection in Anyway, now it seems to work on Wokwi, at least with a simple testing program: |
That is very cool. It gets basic functionality working for writing to the display. To support that, not only will the LCD emulation need to support LCD reads, but the PCF8574 pin values reported will need to be based on how the LCD drives the data pins when a read is done. From my testing I was not able to get reads from the LCD in 4 bit parallel mode working. (interfacing directly to the LCD with pins) For testing LCD reads in 4 bit mode you can use the hd44780_pinIO class. The big daddy is the hd44780_I2Cexp i/o class I2CexpDiag sketch. |
I hope my previous comment didn't come off poorly. |
Thanks for clarifying that! What are the common use cases for reading back from the LCD? |
Most sketch code doesn't do reads from the LCD. The most common use case for reading from the LCD is to read the BUSY status. Any library that uses BUSY status will need to have the ability to read the LCD. The hd44780 library itself doesn't use BUSY. The hd44780 library does check to see if LCD reads are supported, if not, it will put the LCD back into DDRAM mode by setting the cursor position to 0,0 which puts the LCD back into DDRAM mode but does alter the cursor position. While I'm not a fan of these types of things, Does wokwi set a define/macro during the build to indicate that the code is being built in/for the wokwi environment? Long term, it would nice get LCD reads fully working. If going down this path of using wokwi defines to adjust the code for the wokwi environment |
Any news/update on this? |
Sorry for not responding earlier. This is still on my list, but I haven't got to it yet (the list is pretty long...). If I understand correctly, the current situation is that In any case, I'm not very fond of adding a macro that indicates the the code if being built for Wokwi. This will eventually encourage working around simulator bugs instead of fixing them. If you think it's important to fix this, I can make an effort to prioritize adding support for reads in Wokwi. Otherwise, I think we can close this issue and wait to see if any users come up with this request. I'd love to hear your thoughts. |
There is a slight misunderstanding of createChar() The hd44780 library code is designed to work around the lack of read support/capability but it can't work around reads returning garbage. Inability to read from the LCD is an issue that is bigger than just when using a PCF8574. Whether or not this read issue affects hd44780 library users sketch code that use custom characters will depend on if their code sets the cursor position after programming custom characters. Given the hd44780 library is the only LCD library that restores the LCD to DDRAM mode, it is likely that the issue won't be very wide spread. And it won't be an issue for users that take "working" code from other libraries like LiquidCrystal_I2C or LiquidCrystal and switch to the hd44780_I2Cecxp i/o class. So on the positive side, the vast majority of users never use the read capability of the hd44780 library - particularly since no other LCD library supports reading from the LCD so unless they explicitly attempt to read from the LCD they will never see this issue - assuming you added the code to support the hd44780_I2Cexp auto configuration. It will definitely be an issue for the diagnostic tool I2CexpDiag that comes bundled with the hd44780_I2Cexp i/o class examples. This is why I mentioned the possibility of having a macro/define as the library could disable read support to allow things to fall back to working without read support or failing gracefully vs reporting h/w errors. But maybe it is ok to leave the issue there (assuming auto configuration works), and see how many users stumble on it and complain to let that be the driver of setting its priority? Here is summary of what createChar() does, with an updated copy of the code with some new added comments for clarity. creatChar() reads the status register which returns the BUSY bit and the current ddram address. After the character is data is written to CGRAM, the code will restore the cursor position(ddram address) back to where it was prior to programming. Setting the cursor position necessary for two reasons.
|
I guess that was a long way of saying that if you put in the changes to support the hd44780_I2Cexp auto configuration, most users will be happy and won't notice that reads from the LCD are not working properly and return garbage. |
I really appreciate the fact that you take the time to write such detailed explanations, thank you. We now have read support for the hd44870, and it should also work though the PCF8574. I've tested readWrite and it seems to work both with I/O pins and through the I2C extender: I'd love to hear your feedback, and thanks again for collaborating on this! |
Very cool. I'm guessing that was a lot of work. I did notice one issue with the simulator that is related to backlight control that need to be fixed. There are 6 different backpack designs. The simulator will need to decide how it wants to deal with all these different backpack designs. The hd44780_I2Cexp i/o probes through the PCF8574 to determine which one is in use. This appears to be what woki is emulating. You can see that PCF8574 P3 connects to the base of a NPN transistor. Whereas with the PNP designs that require a low on the base to turn on the backlight, it will power up off and will not turn on until the host sets backlight control pin to low. This is where it gets tricky and is non obvious. The hd44780 library probed to incorrectly determine that a RobotArduino LCM1602 backpack with active low backlight control was being used due to reading the incorrect level on pcf8574 P3. All this is a long way of saying, the woki simulator for the lcd backpack needs to read low on the pcf8574 P3 pin so that the hd44780 library can properly determine the backlight control active level. |
Fascinating, I was wondering about the situation with the backlight. You seem to know the ins and outs of these LCD1602 modules! Thanks for the detailed explanation of the backlight detection mechanism. Yes, for now, we'll keep it seems with just the most common design. I've updated Wokwi to read low for P3, so now hd44780 correctly detects the backlight. |
Yay! that is great news. Yeah, I spent quite a bit of time probing these LCDs and backpacks trying to come up with a way to create a method to auto configure the device since so many people were having issues getting their LCDs working. These days, nearly all the backpacks people are purchasing seem to be the design you are emulating. BTW, I also spent LOTs of time with KS0108 type displays. Now THAT is a big can of worms. |
KS0108? Are these the graphic LCDs? p.s. I want to link to one or two of the hd44780 examples from the Wokwi docs for the LCD1602. Any suggested examples? |
KS0108 - yes it is a graphic LCD. Not sure how/where you want to go with the LCD1602 reference page and examples. For hd44780, there are HelloWorld examples for each i/o class, that could be directly linked to in the hd44780 github repository, However, they are not as brief as they could be particularly for pinIO as the pinIO class is setup for an LCD shield to work on the ESP boards so there are some conditionals in it. One thing that might be helpful is to provide a link to a library page in the actual example code for more information when possible. When these links are in the example they are clickable so the user can click on the link to get additional information about the library and its API. Here are some very brief examples like what was done for LiquidCrystal and LiquidCrystal_I2C. For hd44780_I2Cexp:
For hd44780_pinIO
For LiquidCrystal something like this:
|
Awesome, thank you so much! @matititam, can you please add these examples to the Wokwi docs and get in touch with |
Definitely yes. I will start on this ASAP |
For easy dissemination and adoption, it might be nice to have links to the examples as implemented in Wokwi. Three places they could be useful are:
Perhaps something like adding a section for SEE ALSO to the comments in https://github.com/duinoWitchery/hd44780/blob/master/examples/ioClass/hd44780_I2Cexp/HelloWorld/HelloWorld.ino to point back here, and to a Wokwi reference implementation you own. I was thinking something like this: https://wokwi.com/projects/360021172047397889
Given that https://wokwi.com/projects/360021172047397889 ...for example, following the links and advice from that Wokwi sim to the repository and to https://github.com/duinoWitchery/hd44780/blob/master/examples/ioClass/hd44780_I2Cexp/I2CexpDiag/I2CexpDiag.ino with its own Copy button and to get you this output from just a couple mouse clicks:
|
Hello, Developer of Wokwi here.
I learned that you had a negative past experience related to Wokwi. Sorry about this. I'd like to to straighten things out.
How do you feel about working together to have the hd44780 library fully supported on Wokwi?
As far as I understand, we would need to implement hd44780+pcf8574 reading on our end, so that hd44780_I2Cexp::ioread returns a valid value. Unless I got something wrong?
In any case, if you do not feel like spending any time on this and prefer just to close the issue, then I totally understand and respect your decision.
The text was updated successfully, but these errors were encountered: