Hi all ,
My first post, I read all the guidelines and hope didn't missed something...
I'm trying to make 3 functionality work together.
Arduino UNO + LDC I2C 2004 + YF-201 flow meter + DS18B20 thermal sensor.
The 85 degree at startup problem forced me to search for a code that didn't use external libraries (apart the liquidcrystal).
All work despite a blink at any cursor movement and this movement is 1 second (too slow for my taste)
Is possible to speed up the scrolling and make really fixed what is not changing?
I tried to exclude the flow code that stated for delay(1000) for the correct calculation of the flow (is necessary this number) , but the scrolling stay still at 1 sec each movement (always with blink).
I'm a newbie and I managed to arrange this code (maybe with errors but working) but I have no idea where to look or where to make changes.
To add some delay for regulate the scroll seems not work ( How do you change the scroll speed in LCD? - Programming Questions - Arduino Forum )
Many thanks for all the suggestions/supports.
/*ReadDS18B20
ver: 6 Jly 2010
THIS IS A FIRST DRAFT.... WORKS, but scheduled for overhaul.
Simple, simple test of reading DS18B20
connected to nuelectronics.com datalogging shield.
See...
http://sheepdogguides.com/arduino/ar3ne1tt.htm
... for explanation of this code.
Code lightly adapted from code from nuelectronics.com*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
// set the LCD address to 0x27 for a 20 chars and 4 line display
volatile int NbTopsFan; //measuring the rising edges of the signal
int Calc;
int hallsensor = 2; //The pin location of the sensor
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// it's a 20x4 LCD so...
int screenWidth = 20;
int screenHeight = 4;
// the two lines
// line1 = scrolling
String line1 = "Lets roll those Bites !!!";
// line2 = static
String line2 = "My computational RIG ";
// just some reference flags
int stringStart, stringStop = 0;
int scrollCursor = screenWidth;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void rpm () //This is the function that the interupt calls
{
NbTopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
#define TEMP_PIN 4 //See Note 1, sheepdogguides..ar3ne1tt.htm
void OneWireResetA(int Pin) // reset.
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500us
delayMicroseconds(500);
}
void OneWireResetB(int Pin) // reset.
{
pinMode(Pin, INPUT);
delayMicroseconds(500);
}
void OneWireOutByte(int Pin, byte d);
byte OneWireInByte(int Pin);
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start setup
void setup() {
digitalWrite(TEMP_PIN, LOW);
pinMode(TEMP_PIN, INPUT); // sets the digital pin as input (logic 1)
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
attachInterrupt(0, rpm, RISING); //and the interrupt is attached
//9600 to match the data rate being used by the
//serial monitor on my system, which is set to
//the Arduino default. (Sample code published
//by nuelectronics used a faster baud rate.)
delay(100);
Serial.print("temperature measurement:\n");
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>end setup
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start loop
void loop(){
int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);
LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
// ***************************************************************************calibration values start
float RawHigh = 100;
float RawLow = 0;
float ReferenceHigh = 100;
float ReferenceLow = -3.5; // subbed by termocamera + voltmeter check
float RawRange = RawHigh - RawLow;
float ReferenceRange = ReferenceHigh - ReferenceLow;
float RawValue = Whole;
float CorrectedValue = (((RawValue - RawLow) * ReferenceRange) / RawRange) + ReferenceLow;
// ***************************************************************************calibration values end
if (SignBit) // If its negative
{
Serial.print("-");
}
Serial.print(CorrectedValue);
Serial.print(".");
if (Fract < 10)
{
Serial.print("0");
}
Serial.print(Fract);
Serial.print("\n");
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start flow calculation
NbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second for the appropriate calculation
cli(); //Disable interrupts
Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> stop flow calculation
sei();
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start print flow calulation
lcd.init();
lcd.backlight();
lcd.print (" Flow ");
lcd.print (Calc, DEC); //Prints the number calculated above
lcd.print (" L/hour"); //Prints "L/hour" and returns a new line
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end print flow calulation
//********************************************************************************* start thermistor
lcd.setCursor(0,1); //go to the second line
lcd.print("Liquid tank");
lcd.setCursor(12,1);
lcd.print(CorrectedValue);
lcd.setCursor(17,1);
lcd.print((char)223);
lcd.print("C");
//********************************************************************************** close thermistor
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> open static line and scrolling line
lcd.setCursor(scrollCursor, 2);
lcd.print(line1.substring(stringStart,stringStop));
lcd.setCursor(0, 3);
lcd.print(line2);
delay(300);
// lcd.clear();
if(stringStart == 0 && scrollCursor > 0){
scrollCursor--;
stringStop++;
} else if (stringStart == stringStop){
stringStart = stringStop = 0;
scrollCursor = screenWidth;
} else if (stringStop == line1.length() && scrollCursor == 0) {
stringStart++;
} else {
stringStart++;
stringStop++;
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> close static line and scrolling line
cli();
Serial.print (Calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints "L/hour" and returns a new line
delay(5000); // 5 second delay. Adjust as necessary
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end loop
void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}
void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}
d=d>>1; // now the next bit is in the least sig bit position.
}
}
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;
for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(50);
d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return(d);
}