I am a relative newbie to the Arduino IDE, but I had this code running on an ATtiny85. I just wanted to add a few more analog ins. I thought it would be a straight forward port. The code compiles and uploads. When I connect the MH-Tiny ATtiny88 to the LCD and supply power, 'Voltage:' and 'Flow' are displayed on the LCD, but the values from the analogread are not displayed.
The code is below.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Voltage:");
lcd.setCursor(0, 1);
lcd.print("Flow:");
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// read the input on analog A2:
int sensorValue = analogRead(2);
float voltage = float(sensorValue)*(5.0/1023.0);
// read the input on analog A0:
sensorValue = analogRead(0);
float flowRate = float(sensorValue)*(5.0/1023.0);
// print out the values you read:
lcd.setCursor(12, 0);
lcd.print(String(voltage,2));
lcd.setCursor(12, 1);
lcd.print(String(flowRate,2));
}
Again, this works when uploaded to an ATtiny85, but it seems to hang in the Loop function. It is almost like it doesn't enterthe loop.
You need to check up the ATtiny 85 and 88 and compare. Something is different from one to the other.
What made You think they are compatible?
How is the wiring made? Using breadboards?
As far as I can tell, the ATtiny 85 and 88 are pretty compatible similar. I did change the pinouts numbers to match the 88.
Also, I do change the board from ATtiny 85 to ATtiny 88.
The LCD does display ‘Voltage:’ and ‘Flow:’, but no values. I removed all the circuitry except the LCD connected to the SDA and SLC pins, so the analog in should read just the default value.
I am able to run the blink example sketch on the 88.
Pretty compatible might not be good enough. Board pins would be unsafe to compare. Is the core controller chip the same? Different chips often differs regarding timers etc.
No, the core chip is not the same. The core chip on the ATtiny85 board is the ATtiny85 chip and the corechip on the MH-Tiny ATTINY88 Micro Development Board 16Mhz is the ATtiny88.
I’m using the ATTinyCore and I’ve included the correct ‘Wires’ and the ‘LiquidCrystal_i2C’ libraries. I am compiling for the appropriate board.
Also, the LCD power is coming directly from a regulated power supply instead of the board. I think it was drawing too much current for the ATtiny85 board.
Maybe I’m looking in the wrong place. Since the LCD is being displayed, initially, but it doesn’t seem like the Loop is actually being entered. Maybe the problem is with the LCD board connection.
We were thinking alike. I moved the lcd.print commands to the Loop and can see the 'Voltage:' and 'Flow:', but no values. I then commented out the lcd.print(voltage), and lcd.print(flow) lines and added lcd.print("HI") and lcd.print("BYE"). They appeared. Then, I commented them out the test lines and casting the sensorValues to a float and printed out the sensorValue. I now see an integerValues. I connected the center out of potentiometers to the A0 and A2 pins and I can see the integerValues change. It appears the problem is with the casting to a float. Any recommendations?
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
// read the input on analog A2:
lcd.setCursor(0, 0);
lcd.print("Voltage:");
int sensorValue = analogRead(2);
// float voltage = float(sensorValue)*(5.0/1023.0);
// print out the value you read:
lcd.setCursor(12, 0);
lcd.print(String(sensorValue));
// lcd.print(String(voltage,2));
// lcd.print("HI");
// read the input on analog A0:
lcd.setCursor(0, 1);
lcd.print("Flow:");
sensorValue = analogRead(0);
float flowRate = float(sensorValue)*(5.0/1023.0);
// print out the value you read:
lcd.setCursor(12, 1);
lcd.print(String(sensorValue));
// lcd.print(String(flowRate,2));
// lcd.print("BYE");
}
A step forward. Drop the conversion using string. lcd.print does that.Make sure there is place for the characters of the printed value. Locating to position 12 there are only 4 positions left. There's no wrap around in those lcd's. Rather, strange things happen.
A follow up - I created a test variable floatValue and then tried printing the value. The a blank appears. When I try separate the casting and printing, the code will not compile.
OK, I'm started to look at how much memory the sketch uses. On the ATtiny85 it uses 94% of the program storage space and on the MH-Tiny it uses ~104% of the memory space. My question is can I trim some of the 'LiquidCrystal_I2C' library, since I am only using a few functions. If so, can you point me to any resources?