By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Allendale Jan 24th

Display for Arduino

All Topics | Latest Posts

Search for:  in Thread Title in  
Peter Bell20/11/2020 11:04:45
338 forum posts
155 photos

Hello Not really model engineering but at least I'm using my Myford to make the parts!

As a fairly inexperienced Arduino user I am building a dedicated weighing scale using a 1kg load cell.

Its all working fine using a lcd display but what I would like is use a larger display and this where it gets difficult as there so many variations to choose from. Tried a max 7219 without much success also some tft but all seem difficult to use, at least for me!

Can anyone reccomend an easy to use current larger display that worked for them, say 1.8" or 2.2"?

Thanks Peter

Andy Stopford20/11/2020 20:18:27
59 forum posts
1 photos

You need the 7-segment display with i2c backpack - that way there are only two data lines to connect up. They are readily available from ebay and look really good. Unfortunately I've only used one with a Raspberry Pi zero, so I can't give you the C code to make one work (I used Python for the Pi, and the libraries are different anyway).

Hopefully the following link to Adafruit's information and instructions won't fall foul of the forum rules:

https://learn.adafruit.com/adafruit-led-backpack/

edit: Sorry, the ebay ones are SPI rather than i2c; they should be similar to get working, but for simplicity, it might be best to use the Adafruit ones - if you're in the UK, Pimoroni sell them - they cost a bit more than the ebay ones, unfortunately. 

Edited By Andy Stopford on 20/11/2020 20:27:24

duncan webster20/11/2020 23:15:35
avatar
2929 forum posts
34 photos

I think you want one of these TM1637

I've not used this particular one, I've used 8 digit and other 4 digit serial displays, much better than LCD for visibility, but limited scope of non numeric characters

Ady120/11/2020 23:29:24
avatar
4127 forum posts
576 photos

The max 7219 is good with the MD_Parola library but it uses a lot of memory

There's a chap here who has made an LCD version with teeny code

The parola library is worth the extra effort though, because it lets you do virtually anything with an LED dot matrix, pins 10 11 and 13 have given me the least problems so far

an awful lot of examples are like crippleware for a beginner with the arduino, but small tweaks suddenly make all the difference

Coding is still the same old teeth grinding brain squeezing grope in the dark subject that it was 20 years ago but at least the arduino can give you a leg up and start talking to stuff

I think the problem with dot matrixes is you have to tell it EVERYTHING, so you get stuff like below x 100s to define every character or shape, like every dot in newsprint

//////////////

const char font5x7 [] PROGMEM = {      //Numeric Font Matrix (Arranged as 7x font data + 1x kerning data)
    B00000000,  //Space (Char 0x20)
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    6,

    B10000000,  //!
    B10000000,
    B10000000,
    B10000000,
    B00000000,
    B00000000,
    B10000000,
    2,

    B10100000,  //"
    B10100000,
    B10100000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    4,

    B01010000,  //#
    B01010000,
    B11111000,
    B01010000,
    B11111000,
    B01010000,
    B01010000,
    6,

 

Edited By Ady1 on 20/11/2020 23:48:02

Ady121/11/2020 00:05:51
avatar
4127 forum posts
576 photos

If you can dump your readings into the serial monitor this should transfer them to a 7219

Just add these lines to your routine, tweaking the names of variables as required

I'm assuming your readings are floats and you have a 4 module 7219

-------------------------------

#include <MD_Parola.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10


MD_Parola P1 = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

String J;

float weight;

void setup()

P1.begin();

void loop()

J=String(weight);

P1.print(J);

 

---------------------------------------

Somewhere in your void loop() will be a

 Serial.print(weight);

line for printing your weighing sensors output to the monitor, the variable in brackets is your float

omg...I hate code...

Edited By Ady1 on 21/11/2020 00:25:51

Peter Bell21/11/2020 09:48:58
338 forum posts
155 photos

Many thanks for the help, hesitated asking but pleased I did! The power of this site is amazing.

Never heard of an I2c backpack so ordered some Adafruit bits also a TM1637 to try. Nice tutorial on the Adafruit.

Meanwhile Ady I'll have a go with the Parola suggestion but looks far more than what I need. Copied the code and got it to compile after adding some curly braces. Added to my weighing sketch but its doing some funny things with the Max display, need more time to play, hopefully later.

Ady121/11/2020 10:18:15
avatar
4127 forum posts
576 photos

Don't forget your wires on the arduino, use 10 11 an 13

Pasting your current code in here would be the simplest route

Ady121/11/2020 11:46:09
avatar
4127 forum posts
576 photos
Posted by Peter Bell on 21/11/2020 09:48:58:

Copied the code and got it to compile after adding some curly braces.

It needs to be done in steps

1. Get your weighing machine outputting data to the computer monitor

2. connect up the 7219

3. insert my code into your weight routine to transfer data to the 7219

simples! (we wish)

Edited By Ady1 on 21/11/2020 11:53:13

Peter Bell23/11/2020 10:42:02
338 forum posts
155 photos

This is my working sketch at least for weighing and LCD display--must have got it wrong as I cannot make the Parola do anything? Inserted what I think but probably not in the right place! Certaily takes a lot of memory.

Can make the 7219 scroll from other sketches so the module is working.

#include <MD_Parola.h>
#include <HX711_ADC.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P1 = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

const int Reset = 3;
float weight;

String J;

void setup() {
P1.begin();
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print(" Starting ";
lcd.setCursor(0,1);
lcd.print(" 20/11/20 ";
LoadCell.begin();
LoadCell.start(2000);
LoadCell.setCalFactor(851.58); // calibration factor for load cell => strongly dependent on your individual setup Higher for less
pinMode( Reset,INPUT_PULLUP );// Pin3 pull up
lcd.clear();
}

void loop() {
LoadCell.update();
float i = LoadCell.getData();
lcd.setCursor(3,0);
lcd.print("Weight[g]:";
lcd.setCursor(6, 1);

Serial.println(i,1);

J=String(weight);
P1.print(J);


lcd.print(i,1); //Prints weight rounded to 1 place
lcd.print (" ";

if ((digitalRead(Reset) == LOW)) { //Tare
lcd.setCursor(0, 1);
lcd.print(" Tare ";
LoadCell.tare();
delay(500);
lcd.clear();
}
//delay (1000);
}

Ady123/11/2020 11:08:47
avatar
4127 forum posts
576 photos

Can make the 7219 scroll from other sketches so the module is working.

#include <MD_Parola.h>
#include <HX711_ADC.h>
#include <Wire.h>

HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P1 = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

const int Reset = 3;
float i;

String J;

void setup() {
P1.begin();
Serial.begin(9600);


LoadCell.begin();
LoadCell.start(2000);
LoadCell.setCalFactor(851.58); // calibration factor for load cell => strongly dependent on your individual setup Higher for less
pinMode( Reset,INPUT_PULLUP );// Pin3 pull up

}

void loop() {
LoadCell.update();
float i = LoadCell.getData();
lcd.setCursor(3,0);



Serial.println(i,1);

J=String(i);
P1.print(J);




if ((digitalRead(Reset) == LOW)) { //Tare

LoadCell.tare();
delay(500);

}
//delay (1000);
}

Ady123/11/2020 11:12:13
avatar
4127 forum posts
576 photos

Get rid of anything to do with the LCD and give that a go

GL

Peter Bell23/11/2020 11:17:23
338 forum posts
155 photos

Got rid of all lcd but no difference I'm afraid....

Ady123/11/2020 11:49:25
avatar
4127 forum posts
576 photos

Is your weight sensor outputting to the monitor ok?

Peter Bell23/11/2020 11:57:16
338 forum posts
155 photos

Sorry forgot to say---yes working fine

Ady123/11/2020 13:13:17
avatar
4127 forum posts
576 photos

Well All I'm doing is outputting that number (i) to the 7219...

Try changing

Serial.begin(9600);

to

Serial.begin(57600);

And check your LED wiring is ok

EDIT: I have gone and bought a HX711 from the bay because I've finished my last project, arrives in about a week or less

Package include:
1 x Weighing Load Cell
1 x HX711 module

Edited By Ady1 on 23/11/2020 13:48:58

SillyOldDuffer23/11/2020 14:24:53
Moderator
6651 forum posts
1495 photos

Just a suggestion but I see Peter's code says:

J=String(i);
P1.print(J);

The problem may be because P1.print() expects to be given a C string (small s) rather than a C++ String (big S)

Try

P1.print( J.c_str() ); // get a C null terminated string from the C++ String J,

If memory is very short, causing the dreaded 'undefined behaviour', remove big S Strings from the program because they use a lot of memory.

C++ may be much clearer and less error prone with:

J=String(weight);

but pure C is faster and uses far less memory with:

char buf[24]; // big enough to hold a 23 digit number
dtostrf( weight, 6, 1, buf ); // convert weight into C string in buf, minimum 6 characters, with 1 decimal place.
P1.print( buf );

Dave

 

Edited By SillyOldDuffer on 23/11/2020 14:29:53

Peter Bell23/11/2020 18:46:57
338 forum posts
155 photos

Thanks for the suggestions.

Tried thems in many combinations including baud rate but didnt make any difference,

When read i instead of weight got the display to do something, see attached reading a 1kg weight , no weight just flashes the decimal places.

Put the lcd back as it doesnt seem to be the culprit.

Tried another display with identical results, perhaps its time to give up and wait for the I2c display and other to arrive!

 

max display.jpg


#include <MD_Parola.h>
#include <HX711_ADC.h>
#include <Wire.h>
#include // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola P1 = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

const int Reset = 3;
//float weight;

String J;

void setup() {
P1.begin();
Serial.begin(57600);
lcd.begin(16, 2);
lcd.print(" Starting ";
lcd.setCursor(0,1);
lcd.print(" 20/11/20 ";
LoadCell.begin();
LoadCell.start(2000);
LoadCell.setCalFactor(851.58); // calibration factor for load cell => strongly dependent on your individual setup Higher for less
pinMode( Reset,INPUT_PULLUP );// Pin3 pull up
lcd.clear();
}

void loop() {
LoadCell.update();
float i = LoadCell.getData();
lcd.setCursor(3,0);
lcd.print("Weight[g]:";
lcd.setCursor(6, 1);

Serial.println(i,1);

J=String(i);
//P1.print(J);

P1.print( J.c_str() );
lcd.print(i,1);
lcd.print (" ";

if ((digitalRead(Reset) == LOW)) {
lcd.setCursor(0, 1);
lcd.print(" Tare ";
LoadCell.tare();
delay(500);
lcd.clear();
}
//delay (1000);
}

Edited By Peter Bell on 23/11/2020 18:47:21

Edited By Peter Bell on 23/11/2020 18:48:13

SillyOldDuffer24/11/2020 16:44:27
Moderator
6651 forum posts
1495 photos

So it's trying - the output suggests the display is being controlled via SPI but sent the wrong commands, therefore lighting up the wrong segments.

The Parola library depends on the MD_MAX72XX library, and its .h file explains as there is no standard way of connecting the LCD blocks to the converter chip on the end, so the library supports 4 options. They are:

GENERIC_HW, ///< Use 'generic' style hardware modules commonly available.
FC16_HW, ///< Use FC-16 style hardware module.
PAROLA_HW, ///< Use the Parola style hardware modules.
ICSTATION_HW, ///< Use ICStation style hardware module.

Possibly your module isn't an FC16? Anyway, no harm trying the 3 alternatives to

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW

eg.

#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW

or

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW

or

#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW

Dave

Peter Bell24/11/2020 19:24:30
338 forum posts
155 photos

Thanks for the help Dave. Tried all the 3 alternatives but still got the same result I'm afraid. Also tried another display just in case this one is a dud or not what it's marked with identical results.

Think its time to put this display aside and wait until the ones arrive that were suggested earlier in the thread, sure they will bring new problems to the surface and then more learning.

Peter

SillyOldDuffer25/11/2020 09:30:27
Moderator
6651 forum posts
1495 photos

Had another couple of thoughts.

Maybe you have the correct device, wiring, and HARDWARE_TYPE, but are sending it data it can't cope with. The floating point number generated by:

J=String(i); // Could send too many characters to fit the display, or the decimal point is illegal punctuation.

(Floating point numbers change size depending on the result. By default String does 2 places of decimals eg String(1.0/3) gives "0.33", but watch out for the likes of 1000000.0/3 giving 333333.33. The Parola documentation looks as if punctuation is allowed, so the decimal point should be ok.)

Test by assigning some short constants to J in your code , to see if they work. Eg.

J=String("ABC" ) ; // Note - fits in a 4-cell block
if that works then

J=String("123" )  ;
& if that works

J=String("1.3" ) ;
& if that works

J=String(1.3);

Assuming all that fails, have you tried any of Parola's examples? (See File->Examples menu )

This one does nothing but say 'Hello', always a good first step to prove the basics are working. If Parola's own example can't be made to work, suspect wiring error or dud device. Note HARDWARE_TYPE needs to change to do your FC31. If the LEDs display hello, experiment by sending it Strings as above.

// Program to demonstrate the MD_Parola library
//
// Simplest program that does something useful - Hello!
// Uses the Arduino Print Class extension
//
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//

#include
#include
#include

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 11

#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

void setup(void)
{
P.begin();
P.print("Hello!" );
}

void loop(void)
{
}

 

 

Edited By SillyOldDuffer on 25/11/2020 09:31:39

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Latest Forum Posts
Support Our Partners
EngineDIY
Eccentric July 5 2018
cowells
Warco
ChesterUK
emcomachinetools
Eccentric Engineering
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

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.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest