LCD 16x2 failed to display Hello world using NodeMCU1.0 - arduino

I am doing a small project to display text on LCD using NodeMCU1.0. The problem is that the text is not displayed when I upload the sketch "Blank screen only"?
Any help?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
// Arduino UNO => PIN 4 = SCL, PIN 5 = SDA
// NodeMCU Dev Kit => D1 = SCL, D2 = SDA
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.print("Hello World");
}
void loop(){
}

LiquidCrystal_I2C lcd(0x27, 20, 4);
change to...
LiquidCrystal_I2C lcd(0x27, 16, 2); //for 16x2 lcd.
then compile and upload ur code, it may be helpful for u.

Related

Ethernet.begin() preventin lcd.print() with 16x2 display

I am trying to implement a webserver using the W1500 shield (I think it's called that) that also links to a 16x2 LCD and some DHT22 sensors. In my setup function, I have Ethernet.begin(mac, ip); but I can only utitlize the lcd.print() function before calling Ethernet.begin(). After calling this, any lcd.print() does not have any effect (even in the loop, the print function does nothing).
What would cause this and how can I get around this?
Thank you!
(This is my first post, I'm bound to have done something wrong so please let me know!)
#include "DHT.h"
#include <SPI.h>
#include <Ethernet.h>
#include <Vector.h>
#include <LiquidCrystal.h>
#define DHTPIN1 6
#define DHTPIN2 7
#define DHTPIN3 8
#define DHTTYPE DHT22
DHT dht[] = {
{DHTPIN1, DHT22},
{DHTPIN2, DHT22},
{DHTPIN3, DHT22},
};
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
byte ip[] = { 10, 0, 0, 99 };
EthernetServer server(80);
float h[3];
float t[3];
float tf[3];
float avgTempC = 0.00;
float avgTempF = 0.00;
float avgHumid = 0.00;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(16, 2);
// THIS CORRECTLY PRINTS TO LCD
lcd.print("TEMP: HUMID:");
for (auto& sensor : dht) {
sensor.begin();
}
Ethernet.begin(mac, ip);
server.begin( );
// HERE IS WHERE IT DOES NOT WORK
String avgTString = String(avgTempF);
String avgHString = String(avgHumid);
lcd.setCursor(0, 1);
lcd.print(avgTString + "F");
lcd.setCursor(8, 1);
lcd.print(avgHString + "%");
Serial.print("server.begin() called\n");
}
void loop() {...}
You did not mention which ethernet board and which microcontroller board you actually use.
Please check which pins are used by your ethernet shield. Please have a look at the technical description of your ethernet shield.
If you have - for example - an Arduino Ethernet Shield V1, you find the details here:
https://www.arduino.cc/en/Main/ArduinoEthernetShieldV1
Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work.
You cannot use these pins to communicate with the LCD - at least if the LCD does not also use SPI (e.g. if it is connected via 74HC595 shift registers) and even then, you'd have to deselect the other SPI devices and then select the LCD device.
For details, see:
https://www.arduino.cc/en/reference/SPI

Connect nodemcu with 1602 lcd without I2C

I want to connect Nodemcu esp8266 and I2C 1602. I just want to show some text from esp8266 at I2C without any other sensor/hardware in between. What should be the pins' connection between the Nodemcu and I2C?
I would be very thankful if somebody please tell me the comparison of Nodemcu and Arduino pins?
Actually, there are a couple of examples to do this, but there is a library for I2C connection of common 16x2 LCD converters like this:
Just grab the library and put it in your libraries directory and use one of the examples:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0, 2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2, 3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
}

Arduino can't output in both led screen and serial monitor at the same time

I am trying to have Arduino output on both LED screen using the LiquidCrystal library, and on Serial Monitor (later to a txt file or something like that).
In my code, I commented out Serial.begin(9600) and then the screen outputs correctly, but as soon as I include it, the serial monitor outputs fine but the screen flips out and outputs gibberish.
I'm fairly new and I know there's something basic I don't know like 9600 should be augmented because so much power is needed maybe?
#include <LiquidCrystal.h>
#include <DHT.h>
#include <math.h>
/*
* Cannot do both screens and log in the console.
* Currently Serial 9600 is commented out, to allow to print on the screen
* Need Fixing
*/
#include "DHT.h"
#define DHTPIN 8 // what digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
void setup() {
//Serial.begin(9600);
Serial.println("Temperature Recorder");
dht.begin();
// Now LiquidCrystal led monitor stuff
lcd.begin(16,2);
lcd.setCursor(2,0);
lcd.print("** Wanet **");
delay(1500);
lcd.setCursor(1,1);
lcd.print("Motherfuckers.");
delay(3000);
lcd.clear();
}
void loop() {
// Wait a few seconds between measurements.
delay(1000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print(" | Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
Serial.println("------------------------------------");
// led screen printing
lcd.setCursor(0,0);
lcd.print("Temp: Humidity:");
lcd.setCursor(0,1);
lcd.print(t);
lcd.print(" ");
lcd.print(round(f));
lcd.print("%");
delay(5000);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("The world");
lcd.setCursor(4,1);
lcd.print("OURS");
delay(6000);
}
Cheers
On the docs of Arduino's Serial
Serial
It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.
You have two options or you don't use those 2 pins
like this
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
or if you must have those pin you might consider to use a library like softwareSerial which emulates the serial communication a pair of pin of your choice. but the serial monitor via USB won't work anyway.
Ah right so if you are using LiquidCrystal lcd(6, 5, 4, 3, 2, 1);
You cannot use serial.println(""); too because they conflict on D1 / TX->
so would it then be possible to use both lcd.print(""); and serial.println(""); if we shift to pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
or am I misunderstanding?
Use other Arduino pins for the lcd display. D1 is shared with serial communication.

Arduino Wire program seems to stop reading bytes after first i2c payload

I am trying to write a program that receives string data from i2c and displays it on an LCD. The first time data is received to the arduino, it renders it, however subsequent i2c payloads are ignored. My onReceive function has a status line display on the second line of the lcd which display the seconds() field from the timer chip. The seconds number does not seem to increment. However, the per-second dot flash as rendered in loop() does continue to blink, so the mcu is not frozen.
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Time.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
}
void loop()
{
lcd.setCursor(15,1);
if (second() % 2 == 0)
lcd.write(".");
else
lcd.write(" ");
delay(100);
}
void receiveEvent(int howMany)
{
//char buf[howMany];
int i=0;
char output[16];
lcd.clear();
while(Wire.available())
{
char c = Wire.read(); // receive byte as a character
lcd.setCursor(i,0);
lcd.write(c);
i++;
//buf[i++]=c;
//buf[i+1]=0;
}
lcd.setCursor(0,1);
sprintf(output,"s%dNB%dI%d",second(),howMany,i);
lcd.write(output);
}
Your Arduino may be trapped in here:
while(Wire.available())
{
//...
Use:
if(Wire.available() > 0) {
//stuff
}
instead.

Making a button do something on Arduino TFT touchscreen

so I have an Arduino MEGA2560 and a TFT shield touchscreen. I used one of the examples to make 2 buttons to display on screen, by just using drawRect(). But how do I make these 2 boxes do something when I press them? I know the coordinates for these 2 boxes, so how do I make them "sense" the touch and transist into another screen of display? Maybe a example of code would be great help! thanks.
My current code is below: you could add the necessary parts to it.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
void setup(void) {
Serial.begin(9600);
progmemPrintln(PSTR("TFT LCD"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
progmemPrintln(PSTR("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
progmemPrintln(PSTR("Found ILI9328 LCD driver"));
} else if(identifier == 0x7575) {
progmemPrintln(PSTR("Found HX8347G LCD driver"));
} else {
progmemPrint(PSTR("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h)."));
progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!"));
progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring"));
progmemPrintln(PSTR("matches the tutorial."));
return;
}
tft.begin(identifier);
progmemPrint(PSTR("Text "));
Serial.println(startText());
delay(0);
progmemPrintln(PSTR("Done!"));
}
void loop(void) {
startText();
delay(9999999);
}
unsigned long startText() {
tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.println();
tft.println();
tft.setTextColor(GREEN); tft.setTextSize(2.8);
tft.println("Welcome ");
tft.println();
tft.setTextColor(WHITE); tft.setTextSize(2.5);
tft.println();
tft.drawRect(5, 150, 110, 110, YELLOW);
tft.drawRect(130, 150, 110, 110, RED);
tft.setCursor(155, 170);
tft.setTextColor(RED);
tft.println("OFF");
tft.fillRect(5, 150, 110, 110, YELLOW);
tft.fillRect(13, 158, 94, 94, BLACK);
tft.setTextColor(GREEN);
tft.setCursor(20, 170);
tft.println("ON");
return micros() - start;
}
// Copy string from flash to serial port
// Source string MUST be inside a PSTR() declaration!
void progmemPrint(const char *str) {
char c;
while(c = pgm_read_byte(str++)) Serial.print(c);
}
// Same as above, with trailing newline
void progmemPrintln(const char *str) {
progmemPrint(str);
Serial.println();
}
You need the Touch screen lib
#include <TouchScreen.h>
//inside loop
TSPoint p = ts.getPoint();
// Retrieve a point
p = ts.getPoint();
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\tPressure = "); Serial.println(p.z);
Here is an UART TFT LCD, it supports WYSIWYG editor to build your GUI in PC and download it via USB.
It can be controlled by Arduino via UART, so just use the Serial.print() you can make it display many images. And you can even build Font by yourself and download to the LCD.
See https://www.indiegogo.com/projects/nextion-a-cost-effective-high-performance-tft-hmi/x/4467372

Resources