![]() |
Forum Index : Microcontroller and PC projects : I2C Support needed
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Just coming back to topic! I need some tutorial how get some simple characters to a HD44780 LCD via I2C without a library as there is none implemented for the CMM2 ![]() ![]() | ||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
And by the way and not to forget: Thanks for your support, guys! ![]() ![]() ![]() | ||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
There is no support for I2C HD44780 LCD displays in MMBasic on *any* platform, only the parallel interface. The only way to drive the I2C adapter is to squirt the necessary commands and characters down the I2C interface. The easiest way to do that is probably by using the library that I suggested. :) You can, of course, take it to pieces and just implement the bits that you want. If you have a look at the zip file that I posted (just before things got a little diverted :) ) you'll find that it contains a BAS program that includes both the library and some test routines for it. Just load it into your CMM2, make the change that I suggested and see if it works. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Thanks Mick, I already looked at it and will go on checking up. But I also want to start understanding the whole issue, so for squirting it as you say. How will I get a simple letter being displayed? Open I2C, Writing some Hex and then Closing I2C or something? I just need some draft to follow and starting to understand. PS: ... "Hex" according to the corresponding Datasheet?! Edited 2021-09-29 04:34 by Poppy ![]() ![]() | ||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
The Datasheet is quite easy to understand and it is a childs play to program each letter in 8 bits with simple triggering https://www.sparkfun.com/datasheets/LCD/HD44780.pdf But I do not get how to pass the I2C Module with the MMBASIC given commands. ![]() ![]() | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
I've used those I2C 16x2 LCDs with a PICAXE, and if the firmware isn't set up to do the job for you, it's not trivial, because they use "nibble" commands--half a byte, 4 bits at a time. I think it would take a lot of datasheet puzzling to work it out, along with seeing what the Arduino library does if the links Mixtel90 provided don't help you. Edited 2021-09-29 04:49 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
I guess finally it will be easier to leave those I2C -Modules out for directly taking 10 pins and addressing each bit parallely or just defining some functions for it. Just as it is implemented for the Picomite and all Maximites earlier than CMM2. I2C sucks! ![]() ![]() | ||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
As lizby says, it's not a trivial thing. You have to send command bytes as well as characters. The library sorts all that out for you and gives you some simple commands to use: LCDI2C(LineNum,CharPos,Text$) Display string Text$ on LineNum of the display starting at CharPos LCDI2C_Clear() Clears the LCD LCDI2C_Init(I2CAddr) Initialise the I2C and LCD LCDI2C_Close() Close the I2C LCD LCDI2C_BacklightOn() Turn LCD backlight ON LCDI2C_BacklightOff() Turn LCD backlight OFF You can also send Command and Data bytes to do things like controlling cursor visibility and creating custom characters using: LCDI2C_CMD(Byte) Send a COMMAND byte to the LCD, ie RS=0 LCDI2C_DATA(Byte) Send a DATA byte to the LCD, ie RS=1 And you should never need these. :) LCDI2C_DirectSend(Byte) Send a BYTE to the LCD - used internally by the lib LCDI2C_WireWrite(Byte) Write a byte onto the I2C bus to the LCD There's no simpler way of using the I2C adapter, I'm afraid. MMBasic does support the parallel interface using 6 pins: LCD INIT d4, d5, d6, d7, rs, en Edited 2021-09-29 05:10 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Thanks, but actually I am not looking for the easiest way, just a way to specifically comprehend I2C stuff. Doing it the binary way is more operating expense than using the library but it is more tangible for me. No I have to get what this module does to transform bits and bytes and how to talk to it. PS: Of course I am still following your instructions autonomously as well. Edited 2021-09-29 05:15 by Poppy ![]() ![]() | ||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
MMBasic does support the parallel interface using 6 pins: LCD INIT d4, d5, d6, d7, rs, en Sadly not here Cmm2 Manual page 53): Special Devices LCD displays, Real Time Clocks (RTC) and keypads are not supported in the Colour Maximite 2. These can all be implemented in BASIC. That is what I am looking for How To! ![]() ![]() | ||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
Oh! I hadn't realized that the CMM2 didn't support them at all. They are on the micromite, PicoMite and F4. Looks like the I2C way is the best one then, even if it means you have to include the library routines in your program. They aren't big - after all, they had to fit in a micromite. :) Your HowTo is: Connect the display Load the library use the above commands :) The display data sheet will let you know what the special commands are and what they do. The commands sent over I2C are (more or less) the same as would be sent over the parallel interface, but are serialized. The adapter receives the I2C, filters a few commands to change them and send them out to the display pins in parallel. The changed stuff tends to be for backlight control I think. It also provides the toggling for the control pins. You could also rig up the 6 connections and drive it in MMBasic. IIRC you need the top 4 data pins, EN and RS. Ground the lower 4 data pins and RW. You need to write a little routine to send a data byte and a second to send a control byte. Then you write one to send a character, one to clear the display and one to position the cursor. It's all a little awkward, but doable. Edited 2021-09-29 05:44 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Yes but simply using libraries is so Arduino ![]() OK, I got you and thanks for it, I will check it out. ![]() ![]() ![]() | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Sadly, that I2C 16x2 lcd is probably one of the worst devices with which to try to learn generic i2c because of the nibble bus to the lcd which the backpack uses. Much better, to my mind, would be the mcp23017. You still have commands and data to deal with, but there are mmbasic examples available. Or eeproms like those on the ds3231 modules. Edited 2021-09-29 06:26 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
it is a Microsoft-Keyboard PS: I just corrected my rejected posting and it went through new experience for me still some tasks to check up Next time your post gets rejected, zip up a copy of the offending text and post it as an attachment here and I will try and find out why it got rejected. I did offer to provide a short program to 'sanitise' the clipboard before posting it's contents for another user who was having similar problems but he declined the offer. My offer still stands. The code simply takes the clipboard contents, converts some of the more obvious things like 'micro symbol' to u and the pound symbol to UKP etc. It then removes all remaining non ASCII characters before returning the text to the clipboard. I use it in MMEdit to check for non-ASCII code fragments. Jim VK7JH MMedit |
||||
PeterB Guru ![]() Joined: 05/02/2015 Location: AustraliaPosts: 655 |
G'Day All http://www.fruitoftheshed.com/MMBasic.Driving-LCD-with-I2C-interface-using-a-Micromite-5-3.ashx I think I have been using this but it has been a while. Peter |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
http://www.fruitoftheshed.com/MMBasic.Driving-LCD-with-I2C-interface-using-a-Micromite-5-3.ashx I think I have been using this but it has been a while. Peter Thanks! together with the Datasheet I get a clearer view https://www.nxp.com/docs/en/data-sheet/PCF8574_PCF8574A.pdf ![]() ![]() | ||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Still more http://www.fruitoftheshed.com/MMBasic.AllPages.aspx?Cat=MMBasic.i2c I think now I got enough basics to breed on! Thanks to all! ![]() ![]() | ||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Hi PeterB, Good, comprehensive piece of code. This should work on a CMM2, maybe you have to un-comment the 2 delays. The CMM1 needed them, and the CMM2 is definitely faster. Poppy: the example mentions 2 different type of wiring between the LCD and the PCF8574. Maybe checking the connections between the LCD pins and the PCF8574 is wise (visual or with multimeter). Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7938 |
That is a lovely piece of code and commenting, PeterB! It goes to show, you can never have enough comments. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Poppy![]() Guru ![]() Joined: 25/07/2019 Location: GermanyPosts: 486 |
Good, comprehensive piece of code. Yes it is! Poppy: the example mentions 2 different type of wiring between the LCD and the PCF8574. Maybe checking the connections between the LCD pins and the PCF8574 is wise (visual or with multimeter). Thanks for that hint! ![]() ![]() | ||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |