Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 13:31 19 May 2024 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 LCD

     Page 1 of 4    
Author Message
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:52pm 04 Jan 2014
Copy link to clipboard 
Print this post

Hi

I thought I would share my little program I use with a cheap EBAY I2C
LCD interface.



These are very cheap seem to work quite well.

I2C LCD

The attached file will drive a character LCD with the following commands
ClearScreen -- Clears Screen
LCDLine X, "Text" -- Writes the "Text" to Line X Max 4 Line LCD
Light = %B1000 -- Turns the Backlight on use before LCDLine
Light = %B0000 --Turns the backlight off use before LCDLine

Don't forget the pullup resistors on the I2C
The dip switches all need to be in the on position for address &H20

2014-01-05_094340_I2CLCDS.zip

Regards
Jman
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 815
Posted: 09:55am 05 Jan 2014
Copy link to clipboard 
Print this post

Hello Jman,

thanks a lot for sharing your program! That's exact what I am looking for - I bought two four-line displays last week and want to use it over I2C!

Many greetings

Frank
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 11:08am 05 Jan 2014
Copy link to clipboard 
Print this post

You can buy I2C LCD Displays see here I2C LCD
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:18am 05 Jan 2014
Copy link to clipboard 
Print this post

Nice find Paul

Those adapters have a different layout to the one I have linked
the software will need a few minor changes to make it work

Regards
Jman
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 11:48am 05 Jan 2014
Copy link to clipboard 
Print this post

OOPS I copied the link to Email by mistake.
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 05:56pm 05 Jan 2014
Copy link to clipboard 
Print this post

Members might be interested to have a go at creating their own PIC based i2c slave devices.

It is easier than you think. Any device that produces digital or analogue signals can be turned into an i2c slave for interfacing to a MM or other i2c master.

I have made quite a number of variations based on the PIC16F88 and 819 chips to allow all the functions of that chip to be accessed by the i2c bus. I have the source code for a "blank" slave for those interested plus the source code for my device slaves.

It has long been a source of puzzlement for me that the i2c bus is largely overlooked by the hobby society. Is it perceived as too hard?
David M.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 06:13pm 05 Jan 2014
Copy link to clipboard 
Print this post

I am beginning to enjoy I2C.
What I would really like is a multichannel counter.
8 channel, 32 bit would be nice but even 16 bit would be useable.

Jim
VK7JH
MMedit   MMBasic Help
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:01pm 05 Jan 2014
Copy link to clipboard 
Print this post

  Quote  What I would really like is a multichannel counter.
8 channel, 32 bit would be nice but even 16 bit would be useable.


Now that would be a challenge. I suspect you would have to do it with two chips. One to do the counting and one to do the i2c functions. I have a dual pic board that I have used convert PS2 keyboard to i2c also IR remote to i2c.

By "counter" I take it you mean detect digital input transitions and increment the counter registers accordingly. what would you use it for?

Could be a fun project but not so easy as it sounds.
David M.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 09:33pm 05 Jan 2014
Copy link to clipboard 
Print this post

My current requirements are for a number of water flow meters and some motor speed monitoring.
Also wind speed etc.
The water flow meters output a a few hundred hertz.
I currently use picaxe chips as down scalers but one device to do multiple inputs would be nice.

Using I2C on the Maximite reduces the number of counter inputs.
The slow things like the rain gauge are OK with interupts.

Jim
VK7JH
MMedit   MMBasic Help
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 10:06pm 05 Jan 2014
Copy link to clipboard 
Print this post

@Jim,

Am I right in assuming that you are converting pulse repetition frequency to a count value per unit time e.g pulses per millisecond etc to give a digital representation of speed or flow?

I think this one might use a bit of brain power to sort out.
David M.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 11:22pm 05 Jan 2014
Copy link to clipboard 
Print this post

Most flow meters are reasonably linear in output over a useable range and will have x pulses per litre.
The ones on my house and garden water have 330 pulses per litre.
Jaycar have a low flow one but I wore out a couple so have changed to ones from seeedstudio.
http://seeedstudio.com/
Cheaper and hopefully more reliable.

It is simple maths to end up with litres/minute for display purposes whatever reading period is chosen. I log every 5 minutes but if I want to know when the fitting has come of the sprinkler or the timers have stopped, faster reading for displays and alarms is better.

Jim
VK7JH
MMedit   MMBasic Help
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 12:39am 06 Jan 2014
Copy link to clipboard 
Print this post

@jim

It looks like we are hijacking this thread unless jman doesn't mind. At least we are on topic with the i2c part.

The seeed flow meters look like nice units and reasonably priced.

I can't see it being done with one chip. Maybe two. Let me get my head around an algorithm for sampling 8 inputs. We should be able to poll each counter individually or in bulk dependent upon pulse input rates.

Mean time, I'm learning up on PIC16F1503 for TZA to use as i2c slave/master. A bit different to the 16F88 chip so I have to rewrite my existing source codes and get my head around a few new instructions.
David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 11:53am 06 Jan 2014
Copy link to clipboard 
Print this post

@jim

I slept on the problem and I reckon we can do it with one chip.
Send a write to the i2c to select a channel and start the count then after say 10 seconds, send a stop count and read counter value command.

This would work ok as long as you don't want continuous data in. You should be able to interpolate between successive readings to give "continuous" data for display etc. If need be, higher priority inputs could be read more often and lower ones say, once a minute or so. The "read" time is determined by the duration between start and stop commands of the i2c master (Maximite?)

The i2c slave has a number of programmable addresses so if you wanted more inputs, just add another slave and change the address jumpers. Make sense?

Incidentally, the same chip can be used as e.g. a i2c LCD driver with a slight alteration to the non i2c part of the code (the application block).
David M.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 02:20pm 06 Jan 2014
Copy link to clipboard 
Print this post

  MOBI said  It has long been a source of puzzlement for me that the i2c bus is largely overlooked by the hobby society. Is it perceived as too hard?


Probably. Native I2C is very complex, apparently, and just about any device that uses I2C will be full of timing tables and waveform diagrams, clock-cycles etc - at least this has been true for me, when looking at any I2C stuff.

The beauty of the likes of PICAXE, is that all the complicated management of the bus is taken care of for you - you really just have to specify the slave address, and start writing and reading from the device.

I know MM has I2C ability, but I have never played with it, so I am not qualified to comment on that, but the MM manual, Appendix B which talks about I2C, it says that: "Using the I2C bus is complicated, and if you do not need to communicate with these devices, you can safely ignore this section."

That's usually enough to put most people off, and they will turn to plain serial commands.
Smoke makes things work. When the smoke gets out, it stops!
 
muddy0409

Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 125
Posted: 02:47pm 06 Jan 2014
Copy link to clipboard 
Print this post

I think it's time I took a play with this i2c stuff too.
Luckily, PBP has what appears to be fairly easy access to this with most PIC chips.
That means there is not too much new stuff for an old bloke to have to learn.
Wish me luck.


Don't poo poo conspiracy theories.
Remember that everything ever discovered started somewhere as a theory.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 04:48pm 06 Jan 2014
Copy link to clipboard 
Print this post

  Quote  "Using the I2C bus is complicated, and if you do not need to communicate with these devices, you can safely ignore this section


If you are brain dead that is.

i2c is not much different from serial data except that the data is clocked out by a separate line on the master rather than a baud rate generator.

The MM is very good at being an i2c master as is the picaxe and i2c protocol is not difficult. I think perhaps the fancy name of the bus system gives it a sort of mystique. Nothing could be further from actuality.

Timing diagrams and waveform charts are only necessary to understand if you want to create your own i2c master.

I am more than happy to do a thread on i2c if there is enough interest or following.

Just being able to address around 127 different devices on two pins is awesome.

David M.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 05:51pm 06 Jan 2014
Copy link to clipboard 
Print this post

I remember I started a topic "PIC based I2C devices" back in December 2012. Perhaps if there is enough interest, we could continue from there and let Jman's thread get back on topic.

You don't need a specific i2c capable chip, just as long as it has a pin that can interrupt on edge trigger. But that does need something like a 7400 and a RC differentiator. We won't go there though unless someone is curious enough later on.
David M.
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 07:15pm 06 Jan 2014
Copy link to clipboard 
Print this post

Hi Guys


Please use the thread all you like
I too like the I2C stuff
This is a great chip with 16 I/o ports
Jman's Post

Take a look at this thread
More info

Regards
Jman
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:55pm 06 Jan 2014
Copy link to clipboard 
Print this post

I am also very interested in the I2C stuff.
Currently i have a few arduinos 'talking' to each other.
The great thing about the arduino library code is that it allows it to be a master AND a slave at the same time.
This is great when you have to respond to a message quickly, the master does not need to poll, it just assumes the slave role when not sending.
I have about 8 of them connected on the same bus all sending messages to each other, just as a proof of concept because in reality you often only communicate between two devices.

All the devices are 'listening' for messages and respond accordingly. If they need to send a message, like when you press a button or a sensor detects a certain level it becomes a master and then send the message.

This means that 99.9% of the time the mcu that acts as a 'control center' is a slave! and waiting for messages.
All the sensors and keyboard, joystick etc are masters.

I found that this way it is more event driven and reduces the amount of traffic over the I2C bus drastically. Especially for something like keyboards or joysticks. Only when a key is pressed a message needs to be send. If the 'control center' would be a master then it needs to poll every 10-20 ms.

I like sensors to be 'smart'. Imagine using a temperature sensor. It uses an analog port on your MCU and it needs to be polled to read the temperature. Now imagine you need 20. Suddenly your MCU is not having enough analog ports and you need to redesign. With I2C and 'smart' sensors you could have a sensor with a small mcu with says 4-8 analog ports. The 'control center' would then configure those sensor to for instance send a temperature every second if you need logging, or you configure it to send a message when a certain temperature is reached, etc. Your hardware design is then able to have 1 to a few hundred temperature (or other) sensors easily.
The same for things like relays. Control them through I2C and you can connect as many 'smart relays' as you want. They can even give feedback, detect power, pulse relays, etc..



Edited by TZAdvantage 2014-01-08
Microblocks. Build with logic.
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 10:40pm 06 Jan 2014
Copy link to clipboard 
Print this post

Hi TZA

Having i2c devices that can change sex so to speak does make for a system that is event driven but is probably a bit out of the scope of making "simple" pic (or AVR) based i2c slave devices.

When I start an intro to home grown i2c devices I'll probably continue on from where I started in 2012 in the pic based i2c topic.

Was there any reason you picked the PIC16F1503 chip as it is only a 14 pin device?

I have been rewriting my 7 channel ADC slave to fit the 1503 code and am just about there. The chips haven't arrived yet so I don't have anything to test.


David M.
 
     Page 1 of 4    
Print this page
© JAQ Software 2024