Ian P | 14/08/2017 14:43:41 |
![]() 2747 forum posts 123 photos | Dave I am very new to Arduino and programming (other than basic Basic) but I am keen to make some displays for calipers. I have a couple of Nano's and this morning the postman brought two of the 2x16 blue LCDs with I2C piggyback boards. Before I damage anything or waste hours I would be grateful if you could outline what libraries or other files have to be present to successfully compile and download to a Nano. I understand that the Nano does not have dedicated pins for serial displays unlike some other Arduino models. Ian P |
SillyOldDuffer | 14/08/2017 16:10:11 |
10668 forum posts 2415 photos | Hi Ian, Generalising a bit the main difference between a Nano and a Uno is the size of the board and the way the pins are organised. Here's a pin-out diagram for the Nano. A bit intimidating but the most useful information is the lettering running vertically on the board itself D12 to TX1 on the left, D13 to Vin on the right. They're what you connect to. The Nano uses pins A4 and A5 for I2C. A4 is SDA, A5 is SCL. To connect an I2C device, you link GND to GND, 5V to 5V, SDA to SDA and SCL to SCL. Once the Nano and I2C are connected, plug the Nano into a computer with a USB cable. The computer will power the Nano and display. To program the Arduino, download the IDE from here. Fire it up and use the Tools tab to set the Board type to Arduino Nano. Then use the Tools Tab to confirm that the Port is set correctly. (May not get the port right automatically.) Assuming you have a new sketch rather than are modifying an existing one, use the Sketch Tab to select Include Library. Include Library should give you a list with 'Wire' in it. Select it. #include Under the File Tab find and open the Examples list. In the 'Examples from Libraries' section you should see a few example sketches showing how to use I2C in the raw. These may be useful later. But if all you want to do with I2C is drive an LCD display, then there's a contributed library called LiquidCrystalI2C. It too can be found and loaded from the Sketch tab. Next is an example of a minimalist 'hello world' program. In the IDE, type it in, then Verify and Upload using the tick and right arrow buttons. There will be several Warning Messages, but no Errors. If the display doesn't work, and the wiring is OK, the declaration 'LiquidCrystal_I2C lcd( 0x3f, 16, 2 ) is chief suspect. The 16 and 2 must match the number of columns and rows your display has. 16x2 is the most common but you may have bought bigger. The most likely culprit is the 0x3f. It's the address of the I2C hardware and it varies depending on the whim of the supplier, who doesn't always provide documentation. 0x27 and 0x3f are common but other addresses pop up from time to time. If neither work, I provided a link earlier in this thread to a sketch that scans an I2C device and tells you whatever address is being used. Have fun! Dave Edited By SillyOldDuffer on 14/08/2017 16:14:05 |
Bob Mc | 14/08/2017 16:21:39 |
231 forum posts 50 photos | Hi Dave/Ian... Dave .... glad to hear you have solved the problem, I was confident you would. Ian... I know you asked Dave and perhaps he will give some advice, however if you are new to Arduino and having got hold of two LCD board I would imagine they are the LCD version 1 as mentioned in https://arduino-info.wikispaces.com/LCD-Blue-I2C. I think it best if you get the LCD display program going first ... you need to download the library mentioned at the top of the page of the above website, then there is a small program to download for Version 1. If you have never had a go at these displays previously please note that if you do not see any characters on the display at first or if they seem a bit dull you use the brightness control on the little piggy back I2C board. anyway....best of luck.....Bob..
|
Bob Mc | 14/08/2017 16:22:58 |
231 forum posts 50 photos | Dave.....you beat me to it....!!! |
Ian P | 14/08/2017 16:40:06 |
![]() 2747 forum posts 123 photos | Dave, Bob Thanks for the help, I have to go out until this evening but I will try then to get at least the display up and running. I have actually connected it as described and it lights up with the usual top row of solid blocks. Yesterday I checked both the Nano boards using an example LED flash sketch. The only odd thing I dont understand is what one Nano needs Com3 the other one only talks on Com4. Ian P
|
Ian P | 14/08/2017 21:42:31 |
![]() 2747 forum posts 123 photos | Some progress this evening but I'm struggling to compile the hello world example. I took me a while to work out how to add libraries but I have now run the LCD address finder (mine are 0x27) so I must have got something right. I have actually installed two libraries as the filenames were similar and I was not sure which was the correct one, when the compiler runs it tell me there are two but then uses the liquidcrystal_I2C.h I get a long list of error messages, probably not right to post them here, but the two lines that look relevant are these, LCDtest:10: error: 'lcd' was not declared in this scope 'Liquidcrystal_I2C' does not name a type Ian P
|
SillyOldDuffer | 14/08/2017 21:54:12 |
10668 forum posts 2415 photos | Hi Ian, Doing well if you got something to run! Can you post a copy of what you actually typed for hello world. (it's probably a typo.) Dave PS The capitalisation in LiquidCrystal matters! Edited By SillyOldDuffer on 14/08/2017 21:55:14 |
Ian P | 14/08/2017 22:02:26 |
![]() 2747 forum posts 123 photos | This is copied and pasted from the iDE window. I was surprised earlier but I did discover that case was important! Thanks for your help IanP
#include <Wire.h> #include <LiquidCrystal_I2C.h> Liquidcrystal_I2C lcd(0x27, 16, 2); void setup() { void loop()
|
Ian P | 14/08/2017 22:06:06 |
![]() 2747 forum posts 123 photos | This forum editor is not good for posting code anyway but I have just noticed that I have not put spaces after the lcd.init and the brackets (I presume the space is required) Ian P |
SillyOldDuffer | 14/08/2017 22:07:33 |
10668 forum posts 2415 photos | Hi Ian, As you're discovering it's case sensitive! Liquidcrystal_I2C lcd(0x27, 16, 2); should be: LiquidCrystal_I2C lcd(0x27, 16, 2); The error messages mean 'lcd' didn't get created because there's no such thing as a 'Liquidcrystal_I2C' Fingers crossed, Dave |
duncan webster | 14/08/2017 22:08:14 |
5307 forum posts 83 photos | I've no doubt someone has got in before me, but you've got Liquidcrystal_I2C lcd(0x27, 16, 2); (3rd line) which I think should be LiquidCrystal_I2C lcd(0x27, 16, 2); Case is very important! |
SillyOldDuffer | 14/08/2017 22:14:09 |
10668 forum posts 2415 photos | Posted by Ian Phillips on 14/08/2017 22:06:06:
This forum editor is not good for posting code anyway but I have just noticed that I have not put spaces after the lcd.init and the brackets (I presume the space is required) Ian P I see Duncan is helping too. Good news - in general white space in C/C++ doesn't matter. Usually...
|
Ian P | 14/08/2017 22:16:48 |
![]() 2747 forum posts 123 photos | Success! I changed the c to C and put spaces before the brackets so now I have an LCD full of hellohellohello I really did not realise just how case sensitive it is. Now I can start trying different things. Thanks to all Ian P |
SillyOldDuffer | 14/08/2017 22:18:46 |
10668 forum posts 2415 photos | Hurrah! Don't be afraid to experiment - they're quite hard to damage. Cheers, Dave |
duncan webster | 14/08/2017 23:57:35 |
5307 forum posts 83 photos | So now that it's working on LCD, how about a version using one (or more) of these They are so much brighter and easier to see than LCD, but I've not managed to work out how to insert the decimal point, my project used it as a tacho, and I wasn't particularly interested in non integer, or text and Dave, it's quite easy to damage an Arduino pro mini, get the 5 pin header one pitch out, or find that there seems to be 2 versions with mirror imaged pins. Edited By duncan webster on 14/08/2017 23:57:51 |
Ken Weeks | 15/08/2017 10:32:41 |
![]() 132 forum posts 36 photos | Well we have moved way beyond my original post, nice to see it encouraged so much discussion. I have found a site that gives a schematic and code for a three axis DRO using an Arduino I want to just have one axis "X". I have attached the code and commented out (//) the bits that I think are not needed for a one axis read out. Pins 6 and 7 take the out put from the caliper into the Arduino but I am not sure how to set the out put from the Arduino to the L.C.D. Is it done by the altering "LiquidCrystal lcd(6,5,4,3,2,1); to read "LiquidCrystal lcd(x.x);" where x.x represents a pair of numbers between 1 and 6 i.e "LiquidCrysyal lcd(1,2);" Perhaps somebody who understand coding better than I do would kind enough to check it through to see if it would work or if I need to alter anything else. Thanks in advance Ken
// DRO.ino // AUTHORS : Scrachi // CREATED : 2016-06-10 // INSPIRED BY :martin's useless ans useful creations //< https://sites.google.com/site/marthalprojects/home/arduino/arduino-reads-digital-caliper > // Recuperation de donnees depuis des pieds a coulisse "chinois" // pour affichage sur LCD 20*4 #include <LiquidCrystal.h> int sign; long value; float resu; int resuTmp; char msg[20]; int datapinX = 8; int clockpinX = 7; unsigned long tempmicrosX; //int datapinY = 10; //int clockpinY = 9; //unsigned long tempmicrosY; //int datapinZ = 12; //int clockpinZ = 11; //unsigned long tempmicrosZ; LiquidCrystal lcd(6,5,4,3,2,1); void setup() { lcd.begin(20, 4); pinMode(clockpinX, INPUT_PULLUP); pinMode(datapinX, INPUT_PULLUP); // pinMode(clockpinY, INPUT_PULLUP); // pinMode(datapinY, INPUT_PULLUP); // pinMode(clockpinZ, INPUT_PULLUP); // pinMode(datapinZ, INPUT_PULLUP); } void loop () { //PAC X traitement(clockpinX, datapinX, tempmicrosX, 1); //PAC Y //traitement(clockpinY, datapinY, tempmicrosY, 2); //PAC Z //traitement(clockpinZ, datapinZ, tempmicrosZ, 3); } void traitement(int clockpin, int datapin, unsigned long temps, int axe){ while (digitalRead(clockpin)==HIGH) {} temps=micros(); while (digitalRead(clockpin)==LOW) {} if ((micros()-temps)>500) decode(clockpin, datapin, axe); } void decode(int clockpin, int datapin, int axe) { sign=1; value=0; for (int i=0;i<23;i++) { while (digitalRead(clockpin)==HIGH) {} while (digitalRead(clockpin)==LOW) {} if (digitalRead(datapin)==HIGH) { if (i<20) { value|= 1<<i; } if (i==20) { sign=-1; } } } resu=(value*sign)/100.00; switch (axe) { case 1: lcd.setCursor(0, 0); resuTmp = ((int)resu - resu) * 100; sprintf(msg,"X : %d.%d ", (int)resu, abs(resuTmp)); lcd.print(msg); break; // case 2: //lcd.setCursor(0, 1); //resuTmp = ((int)resu - resu) * 100; // sprintf(msg,"Y : %d.%d ", (int)resu, abs(resuTmp)); //lcd.print(msg); // break; // case 3: // lcd.setCursor(0, 2); //resuTmp = ((int)resu - resu) * 100; //sprintf(msg,"Z : %d.%d ", (int)resu, abs(resuTmp)); //lcd.print(msg); //break; } }
|
SillyOldDuffer | 15/08/2017 11:37:28 |
10668 forum posts 2415 photos | Posted by Ken Weeks on 15/08/2017 10:32:41:
... I have found a site that gives a schematic and code for a three axis DRO using an Arduino I want to just have one axis "X". I have attached the code and commented out (//) the bits that I think are not needed for a one axis read out. Pins 6 and 7 take the out put from the caliper into the Arduino but I am not sure how to set the out put from the Arduino to the L.C.D. Is it done by the altering "LiquidCrystal lcd(6,5,4,3,2,1); to read "LiquidCrystal lcd(x.x);" where x.x represents a pair of numbers between 1 and 6 i.e "LiquidCrysyal lcd(1,2);" ...LiquidCrystal lcd(6,5,4,3,2,1); lcd.begin(20, 4); ... value|= 1< Hi Ken, What you have is very similar to Bob's sketch so it should work. 3 statements need looking at. First, fix a bug by changing: value|= 1< Edited By SillyOldDuffer on 15/08/2017 11:43:01 |
SillyOldDuffer | 15/08/2017 11:45:12 |
10668 forum posts 2415 photos | Wow! Deleting two characters from my last post caused the forum software to throw a wobbler. I never typed it in like that. Eeek. |
duncan webster | 19/08/2017 00:13:15 |
5307 forum posts 83 photos | having followed this thread with considerable interest I went to dig out the old digital caliper I've had stored away for just such an eventuality. Turns out it is a Digimatic (which I seem to think has a different protocol), and doesn't have a plug connection. Am I wasting my time going any further? Edited By duncan webster on 19/08/2017 00:13:37 Edited By duncan webster on 19/08/2017 00:13:58 |
Neil Wyatt | 19/08/2017 07:53:20 |
![]() 19226 forum posts 749 photos 86 articles | A useful post Dave, even for me as a hardened ABV man! Why couldn't they call the library file 'I2C' rather than 'Wire' so it was obvious what to use with 'LiquidCrystal_I2C lcd'? It seems these small details of inconsistent naming plague opensource projects and make it difficult for people to set things up intuitively. I would never have looked for a routine called 'wire' (one_wire perhaps!) making resorting to a tutorial or advice essential. Neil |
Please login to post a reply.
Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!
Sign up to our newsletter and get a free digital issue.
You can unsubscribe at anytime. View our privacy policy at www.mortons.co.uk/privacy
You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.
Click THIS LINK for full contact details.
For subscription issues please see THIS LINK.