PaulS:
do anyone have an idea how to fix it?
Do anyone have any code that they want to share?
haha yes ofc. ArdOS can be downloded here: https://bitbucket.org/ctank/ardos/downloads
Here's the method within the LCD display, which crashes the Arduino
void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
Furtheremore command looks like this:
inline void LiquidCrystal_I2C::command(uint8_t value) {
send(value, 0);
}
The send method looks like this:
void LiquidCrystal_I2C::send(uint8_t value, uint8_t mode) {
uint8_t highnib = value & 0xF0;
uint8_t lownib = value << 4;
write4bits((highnib)|mode);
write4bits((lownib)|mode);
}
write4bits method, note that pulseEnable also call the next method. Therefore it is not showed..
void LiquidCrystal_I2C::write4bits(uint8_t value) {
expanderWrite(value);
pulseEnable(value);
}
ExpanderWrite uses Wire.h to write to the LCD display.
void LiquidCrystal_I2C::expanderWrite(uint8_t _data){
Wire.beginTransmission(_Addr);
Wire.write((int)(_data) | _backlightval);
Wire.endTransmission();
}
This is the code for implementing af task in ArdOS
#include <kernel.h>
#include <mutex.h>
#include <queue.h>
#include <sema.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,20,4); //Where 0,27 is the address of the lcd, 20 is characters and 4 is number of lines
void task1(void *p)
{
while(1)
{
lcd.setCursor(2,2);
lcd.printstr("This is a test");
OSSleep(500); //Sleeps the task for 500 miliseconds
lcd.clear();
OSSleep(500);
}
}
void setup()
{
lcd.init();
lcd.clear();
lcd.backlight();
OSInit(1);
OSCreateTask(0, task1, NULL); //Where 0 is the priority
OSRun();
}
void loop()
{
}