Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:17 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : I2C Support needed

     Page 2 of 3    
Author Message
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 03:49pm 28 Sep 2021
Copy link to clipboard 
Print this post

  Poppy said  Hi all around.

Could somebody please give me a simple but working "Hello World" like this but in MMBASIC
https://www.hackster.io/newproject/how-to-use-lcd-i2c-30bbf0
my LCD-Adress also is "27"

Being so easy for Arduinos I am really stucked right here.


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
Andre ... such a GURU?
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 03:51pm 28 Sep 2021
Copy link to clipboard 
Print this post

  Poppy said  
  Poppy said  Hi all around.

Could somebody please give me a simple but working "Hello World" like this but in MMBASIC
https://www.hackster.io/newproject/how-to-use-lcd-i2c-30bbf0
my LCD-Adress also is "27"

Being so easy for Arduinos I am really stucked right here.


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


And by the way and not to forget:

Thanks for your support, guys!

Andre ... such a GURU?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 04:35pm 28 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 06:33pm 28 Sep 2021
Copy link to clipboard 
Print this post

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
Andre ... such a GURU?
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 06:43pm 28 Sep 2021
Copy link to clipboard 
Print this post

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.
Andre ... such a GURU?
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 06:47pm 28 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 06:55pm 28 Sep 2021
Copy link to clipboard 
Print this post

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!
Andre ... such a GURU?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 07:06pm 28 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 07:14pm 28 Sep 2021
Copy link to clipboard 
Print this post

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
Andre ... such a GURU?
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 07:17pm 28 Sep 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  

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!
Andre ... such a GURU?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 07:33pm 28 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 07:42pm 28 Sep 2021
Copy link to clipboard 
Print this post

Yes but simply using libraries is so Arduino  

OK, I got you and thanks for it, I will check it out.

Andre ... such a GURU?
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 08:25pm 28 Sep 2021
Copy link to clipboard 
Print this post

  Poppy said  Thanks, but actually I am not looking for the easiest way, just a way to specifically comprehend I2C stuff


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: Australia
Posts: 6283
Posted: 09:06pm 28 Sep 2021
Copy link to clipboard 
Print this post

  Poppy said  
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: Australia
Posts: 655
Posted: 02:10am 29 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 06:32am 29 Sep 2021
Copy link to clipboard 
Print this post

  PeterB said  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


Thanks!

together with the Datasheet I get a clearer view

https://www.nxp.com/docs/en/data-sheet/PCF8574_PCF8574A.pdf
Andre ... such a GURU?
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 06:56am 29 Sep 2021
Copy link to clipboard 
Print this post

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!
Andre ... such a GURU?
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 07:04am 29 Sep 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 7938
Posted: 07:21am 29 Sep 2021
Copy link to clipboard 
Print this post

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: Germany
Posts: 486
Posted: 07:26am 29 Sep 2021
Copy link to clipboard 
Print this post

  Volhout said  Hi PeterB,

Good, comprehensive piece of code.


Yes it is!

  Volhout said  

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!
Andre ... such a GURU?
 
     Page 2 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025