Go Down

Topic: "Multi-threading" for handling teleduino and LCD simultaneously (Read 751 times) previous topic - next topic

alexokaban

Hi,

I'm writing a program to control watering and lighting of plants. So far so long the code works without connecting the system to the internet. Now the idea is to also have access through the internet. I'm using Teleduino + MIT App Inventor. The original program uses Softtimer library which is task oriented and removes the loop() function. I'm trying to use the "Teleduino2560EthernetClientProxy" example. This example has a large code section at the loop() function. I copied this code and pasted it as a task of the Softtimer library with a defined timming, to do it; like of 3 to 10 milisecs and simple tasks like reading a input works fine. The issue appears when I try to use the LCD. It seems that the Teleduino code affects the LCD and shows random characters. I know there is a bug of mixing different coding techniques: with and without loop(). Please could you help me out? what am I doing wrong? is it possible to use these libraries together? Thanks a lot! I'm sorry if there are typos.

Code: [Select]

#include <SoftTimer.h>
#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <Teleduino2560.h>

#include <SPI.h>
#include <Ethernet.h>

#include <hd44780.h>    // https://github.com/alexokaban/hd44780
#include <hd44780ioClass/hd44780_pinIO.h>   // Arduino pin i/o class header

// LCD pin setup
const int rs=9, en=10, db4=4, db5=5, db6=6, db7=7;
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// LCD geometry
const int LCD_COLS = 20;    // columnas
const int LCD_ROWS = 4;     // filas

// User configurable variables
byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x** };
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false
char serverName[] = "us01.proxy.teleduino.org"; // Only if useDns is true
unsigned int serverPort = 5353; // Can be set to either 53 or 5353
byte statusLedPin = 8;

// User configurable key, this is used to authenticate with the proxy server
// This is checked against the EEPROM on boot and written if necessary
// The proxy server retreives the key from the EEPROM

// E4516D9F0BE296133E45CDFF947FBA63
byte key[] = { 0xE4, 0x51, 0x6D, 0x9F,
               0x0B, 0xE2, 0x96, 0x13,
               0x3E, 0x45, 0xCD, 0xFF,
               0x94, 0x7F, 0xBA, 0x** };

// Other required variables
byte data[257];
byte dataLength;
byte hexStage;
unsigned long lastInstruction = 0;
unsigned long lastRefresh = 0;
byte stage = 0;

// Declare client object
EthernetClient Client;

// -- Define method signature.
void callBack1(Task* me);
void callBack2(Task* me);

Task teleduino(10, callBack1);
Task read_adc(1000, callBack2);

void setup() {
 
  SoftTimer.add(&teleduino);
  SoftTimer.add(&read_adc);

  // inicializa el LCD
  lcd.begin(LCD_COLS, LCD_ROWS);
 
   // This is here purely to add a bit of padding to the sketch to fix a compiling bug
  // http://arduino.cc/forum/index.php/topic,60649.0.html
  EEPROM.read(0);
 
  // Load presets
  Teleduino2560.loadPresets();
 
  // Set status LED pin
  Teleduino2560.setStatusLedPin(statusLedPin);

  Teleduino2560.setStatusLed(1); // Initialisation
  // Check the EEPROM header and check to see if the key is correct
  // This is to ensure the key is not cleared from the EEPROM
  if(EEPROM.read(0) != '#')
  {
    EEPROM.write(0, '#');
  }
  if(EEPROM.read(1) != 1)
  {
    EEPROM.write(1, 1);
  }
  if(EEPROM.read(2) != '#')
  {
    EEPROM.write(2, '#');
  }
  if(EEPROM.read(395) != '#')
  {
    EEPROM.write(395, '#');
  }
  for(byte i = 0; i < 16; i++)
  {
    if(EEPROM.read(396 + i) != key[i])
    {
      EEPROM.write(396 + i, key[i]);
    }
  }
  if(EEPROM.read(412) != '#')
  {
    EEPROM.write(412, '#');
  }

  // Start network and attempt to connect to proxy server
  Teleduino2560.setStatusLed(2); // Network configuration
  if(useDhcp)
  {
    if(!Ethernet.begin(mac))
    {
      Teleduino2560.setStatusLed(2, false, 10000);
      Teleduino2560.reset();
    }
  }
  else
  {
    Ethernet.begin(mac, deviceIp, dnsIp, gatewayIp, subnet);
  }
  delay(1000);

  Teleduino2560.setStatusLed(3); // Connect to server
  if((useDns && !Client.connect(serverName, serverPort)) || (!useDns && !Client.connect(serverIp, serverPort)))
  {
    Teleduino2560.setStatusLed(3, false, 10000);
    Teleduino2560.reset();
  }
  lastInstruction = millis();

  Serial.begin(9600);
 
}

void callBack1(Task* me) {
 if(Client.connected())
  {
    // What we need to do depends on which 'stage' we are at
    switch(stage)
    {
      case 0: // Wait for start byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage++;
          }
        }
        break;
      case 1: // Reset variables
        dataLength = 0;
        hexStage = 0;
        stage++;
        break;
      case 2: // Instruction byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            stage = 0;
            break;
          }
          if(!hexStage)
          {
            data[0] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[0] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            stage++;
          }
        }
        break;
      case 3: // Data length byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            stage = 0;
            break;
          }
          if(!hexStage)
          {
            data[1] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[1] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            stage++;
          }
        }
        break;
      case 4: // Data
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            if(dataLength == data[1])
            {
              stage++;
              break;
            }
            else
            {
              stage = 0;
              break;
            }
          }
          if(!hexStage)
          {
            data[2 + dataLength] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[2 + dataLength] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            dataLength++;
          }
        }
        break;
      case 5: // Execute instruction and return result
        Teleduino2560.instruction(data);
        Client.write('!');
        for(int i = 0; i < data[1] + 2; i++)
        {
          Client.write(Teleduino2560.hexEncode(data[i] / 16));
          Client.write(Teleduino2560.hexEncode(data[i] % 16));
        }
        Client.write('\n');
        lastInstruction = millis();
        stage = 0;
        break;
    }
  }
  else
  {
    Teleduino2560.setStatusLed(10);
    Teleduino2560.reset();
  }

  // Has the instruction timeout been reached?
  if(millis() - lastInstruction > 30000)
  {
    Client.flush();
    Client.stop();
    Teleduino2560.setStatusLed(9);
    Teleduino2560.reset();
  }

  // Process refreshes every 50ms
  if(millis() - lastRefresh >= 50)
  {
    Teleduino2560.pinTimers();
    Teleduino2560.shiftRegisterTimers();
    Teleduino2560.shiftRegisters();
    lastRefresh = millis();
  }

  // Check to see if reset has been requested
  Teleduino2560.checkReset();
}

void callBack2(Task* me)
  { volatile int adc_value;
    adc_value = analogRead(A0);
    Serial.println(adc_value);

    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(adc_value);
    }

alexokaban

hi.
I've quitted the idea of using the SoftTimer library and want to come back to using the loop() function. I've thought about using a simple state machine to solve this issue. For now I just want to use the Teleduino library + a LCD library. I call the teleduino procedure during the loop and also check a LCD time for refreshing. Once it reachs it, the LCD is written and comes back to loop. But there must be a bug because the LCD shows a random character repeteated all over the screen.

I've never done "multiprocessing" in arduino. I remember back then at school we could debug the program in real time, to see line per line how the processor was processing them and to set up breakpoints, that way we would track the program and it was easier to catch what was happening..

How can I solve this? Is there any silly bug in the code? Thanks a lot!!

Code: [Select]
#include <hd44780.h>    // https://github.com/alexokaban/hd44780
#include <hd44780ioClass/hd44780_pinIO.h>   // Arduino pin i/o class header
#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <Teleduino2560.h>
#include <SPI.h>
#include <Ethernet.h>

// LCD pin setup
const int rs=9, en=10, db4=4, db5=5, db6=6, db7=7;
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

// LCD geometry
const int LCD_COLS = 20;    // columnas
const int LCD_ROWS = 4;     // filas

// the possible states of the state-machine
//typedef enum {  STATE_NONE,
enum {  STATE_NONE, STATE_LCD_START } state = STATE_NONE;;

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;           // interval at which to blink (milliseconds)
const long lcd_time = 1000;

byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 };
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false
char serverName[] = "us01.proxy.teleduino.org"; // Only if useDns is true
unsigned int serverPort = 5353; // Can be set to either 53 or 5353
byte statusLedPin = 8;

/*The different status codes are:
1 flash - Initialising
2 flashes - Starting network
3 flashes - Connecting to server
4 flashes - Authenticated
5 flashes - Session already exists for supplied key (sometimes happens after a quick restart - will work on next auto-restart)
6 flashes - Invalid or unauthorised key
10 flashes - Connection dropped*/

// User configurable key, this is used to authenticate with the proxy server
// This is checked against the EEPROM on boot and written if necessary
// The proxy server retreives the key from the EEPROM

// Key = E4516D9F0BE296133E45CDFF947FBA63

byte key[] = { 0xE4, 0x51, 0x6D, 0x9F,
               0x0B, 0xE2, 0x96, 0x13,
               0x3E, 0x45, 0xCD, 0xFF,
               0x94, 0x7F, 0xBA, 0x63 };

// Other required variables
byte data[257];
byte dataLength;
byte hexStage;
unsigned long lastInstruction = 0;
unsigned long lastRefresh = 0;
byte stage = 0;

// Declare client object
EthernetClient Client;

void setup() {
  lcd.begin(LCD_COLS, LCD_ROWS); 
  // This is here purely to add a bit of padding to the sketch to fix a compiling bug
  // http://arduino.cc/forum/index.php/topic,60649.0.html
  EEPROM.read(0);
  Teleduino2560.loadPresets();    // Load presets
  Teleduino2560.setStatusLedPin(statusLedPin);    // Set status LED pin
  Teleduino2560.setStatusLed(1); // Initialisation
  // Check the EEPROM header and check to see if the key is correct
  // This is to ensure the key is not cleared from the EEPROM
  if(EEPROM.read(0) != '#')
  { EEPROM.write(0, '#');  }
  if(EEPROM.read(1) != 1)
  { EEPROM.write(1, 1);  }
  if(EEPROM.read(2) != '#')
  { EEPROM.write(2, '#');  }
  if(EEPROM.read(395) != '#')
  { EEPROM.write(395, '#');  }
  for(byte i = 0; i < 16; i++)
  { if(EEPROM.read(396 + i) != key[i])
    { EEPROM.write(396 + i, key[i]);  }  }
  if(EEPROM.read(412) != '#')
  { EEPROM.write(412, '#');  }

  // Start network and attempt to connect to proxy server
  Teleduino2560.setStatusLed(2); // Network configuration
  if(useDhcp)
  { if(!Ethernet.begin(mac))
    { Teleduino2560.setStatusLed(2, false, 10000);
      Teleduino2560.reset();  }  }
  else
  { Ethernet.begin(mac, deviceIp, dnsIp, gatewayIp, subnet);  }
 
  delay(1000);

  Teleduino2560.setStatusLed(3); // Connect to server
  if((useDns && !Client.connect(serverName, serverPort)) || (!useDns && !Client.connect(serverIp, serverPort)))
  { Teleduino2560.setStatusLed(3, false, 10000);
    Teleduino2560.reset();  }
  lastInstruction = millis();  }

void loop() {
 
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= lcd_time) {
    previousMillis = currentMillis;
    state = STATE_LCD_START;  } 
 
  process_machine(); 
  teleduino_task(); 
  }

void process_machine () {
  switch (state) {
    case STATE_LCD_START:
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("hola mundo");
    lcd.setCursor(0,1);
    lcd.print(millis());
        state = STATE_NONE;
    break;  }  }

void teleduino_task() {
   if(Client.connected())
  { // What we need to do depends on which 'stage' we are at
    switch(stage)
    { case 0: // Wait for start byte
        if(Client.available())
        { char c = Client.read();
          if(c == '?')
          { stage++;  }  }
        break;
      case 1: // Reset variables
        dataLength = 0;
        hexStage = 0;
        stage++;
        break;
      case 2: // Instruction byte
        if(Client.available())
        { char c = Client.read();
          if(c == '?')
          { stage = 1;
            break;  }
          else if(c == '\r' || c == '\n' || c == '.')
          { stage = 0;
            break;  }
          if(!hexStage)
          { data[0] = Teleduino2560.hexDecode(c) * 16;  }
          else
          { data[0] += Teleduino2560.hexDecode(c);  }
          hexStage = !hexStage;
          if(!hexStage)
          { stage++;  }  }
        break;
      case 3: // Data length byte
        if(Client.available())
        { char c = Client.read();
          if(c == '?')
          { stage = 1;
            break;  }
          else if(c == '\r' || c == '\n' || c == '.')
          { stage = 0;
            break;  }
          if(!hexStage)
          { data[1] = Teleduino2560.hexDecode(c) * 16;  }
          else
          { data[1] += Teleduino2560.hexDecode(c);  }
          hexStage = !hexStage;
          if(!hexStage)
          { stage++;  }  }
        break;
      case 4: // Data
        if(Client.available())
        { char c = Client.read();
          if(c == '?')
          { stage = 1;
            break;  }
          else if(c == '\r' || c == '\n' || c == '.')
          { if(dataLength == data[1])
            { stage++;
              break;  }
            else
            { stage = 0;
              break;  }  }
          if(!hexStage)
          { data[2 + dataLength] = Teleduino2560.hexDecode(c) * 16;  }
          else
          { data[2 + dataLength] += Teleduino2560.hexDecode(c);  }
          hexStage = !hexStage;
          if(!hexStage)
          { dataLength++;  }  }
        break;
      case 5: // Execute instruction and return result
        Teleduino2560.instruction(data);
        Client.write('!');
        for(int i = 0; i < data[1] + 2; i++)
        { Client.write(Teleduino2560.hexEncode(data[i] / 16));
          Client.write(Teleduino2560.hexEncode(data[i] % 16));  }
        Client.write('\n');
        lastInstruction = millis();
        stage = 0;
        break;  }  }
  else
  { Teleduino2560.setStatusLed(10);
    Teleduino2560.reset();  }

  // Has the instruction timeout been reached?
  if(millis() - lastInstruction > 30000)
  { Client.flush();
    Client.stop();
    Teleduino2560.setStatusLed(9);
    Teleduino2560.reset();  }

  // Process refreshes every 50ms
  if(millis() - lastRefresh >= 50)
  { Teleduino2560.pinTimers();
    Teleduino2560.shiftRegisterTimers();
    Teleduino2560.shiftRegisters();
    lastRefresh = millis();  }

  // Check to see if reset has been requested
  Teleduino2560.checkReset();  }

alexokaban

Anyone please?
I've changed the tittle to be more precise.
Maybe, did I choose the wrong forum section?

wildbill

Maybe comment out your call to the Teleduino task. Keep commenting until you get the LCD working. It might be worth writing a simple program that just tests the LCD.

alexokaban

Maybe comment out your call to the Teleduino task. Keep commenting until you get the LCD working. It might be worth writing a simple program that just tests the LCD.
Hi, thanks a lot for you answer!.

Here. I just took out the LCD code and made it sketch. It works fine:

Code: [Select]
#include <hd44780.h>
#include <hd44780ioClass/hd44780_pinIO.h>

const int rs=9, en=10, db4=4, db5=5, db6=6, db7=7;
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

const int LCD_COLS = 20;
const int LCD_ROWS = 4;

enum {  STATE_NONE, STATE_LCD_START } state = STATE_NONE;;

unsigned long previousMillis = 0;
const long lcd_time = 1000;

void setup() {
  lcd.begin(LCD_COLS, LCD_ROWS);  }

void loop() {
 
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= lcd_time) {
    previousMillis = currentMillis;
    state = STATE_LCD_START;  } 
 
  process_machine();  }

void process_machine () {
  switch (state) {
    case STATE_LCD_START:
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("hola mundo ");
    lcd.print(millis());
    state = STATE_NONE;
    break;  }  }



I'm trying to put the above LCD code together with the Teleduino2560EthernetClientProxy example code, which I will include next:

Code: [Select]
/*
  Teleduino2560EthernetClientProxy.ino - Teleduino2560EthernetClientProxy example
  Version 2560-0.1.2
  Nathan Kennedy 2009 - 2014
  http://www.teleduino.org

  This sketch is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#include <EEPROM.h>
#include <Servo.h>
#include <Wire.h>
#include <Teleduino2560.h>

#include <SPI.h>
#include <Ethernet.h>

// User configurable variables
byte useDhcp = true;
byte useDns = true;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress deviceIp(192, 168, 1, 100); // Only if useDhcp is false
IPAddress gatewayIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress dnsIp(192, 168, 1, 1); // Only if useDhcp is false
IPAddress subnet(255, 255, 255, 0); // Only if useDhcp is false
IPAddress serverIp(173, 230, 152, 173); // Only if useDns is false
char serverName[] = "us01.proxy.teleduino.org"; // Only if useDns is true
unsigned int serverPort = 5353; // Can be set to either 53 or 5353
byte statusLedPin = 8;

// User configurable key, this is used to authenticate with the proxy server
// This is checked against the EEPROM on boot and written if necessary
// The proxy server retreives the key from the EEPROM
byte key[] = { 0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00, 0x00 };

// Other required variables
byte data[257];
byte dataLength;
byte hexStage;
unsigned long lastInstruction = 0;
unsigned long lastRefresh = 0;
byte stage = 0;

// Declare client object
EthernetClient Client;

void setup()
{
  // This is here purely to add a bit of padding to the sketch to fix a compiling bug
  // http://arduino.cc/forum/index.php/topic,60649.0.html
  EEPROM.read(0);
 
  // Load presets
  Teleduino2560.loadPresets();
 
  // Set status LED pin
  Teleduino2560.setStatusLedPin(statusLedPin);

  Teleduino2560.setStatusLed(1); // Initialisation
  // Check the EEPROM header and check to see if the key is correct
  // This is to ensure the key is not cleared from the EEPROM
  if(EEPROM.read(0) != '#')
  {
    EEPROM.write(0, '#');
  }
  if(EEPROM.read(1) != 1)
  {
    EEPROM.write(1, 1);
  }
  if(EEPROM.read(2) != '#')
  {
    EEPROM.write(2, '#');
  }
  if(EEPROM.read(395) != '#')
  {
    EEPROM.write(395, '#');
  }
  for(byte i = 0; i < 16; i++)
  {
    if(EEPROM.read(396 + i) != key[i])
    {
      EEPROM.write(396 + i, key[i]);
    }
  }
  if(EEPROM.read(412) != '#')
  {
    EEPROM.write(412, '#');
  }

  // Start network and attempt to connect to proxy server
  Teleduino2560.setStatusLed(2); // Network configuration
  if(useDhcp)
  {
    if(!Ethernet.begin(mac))
    {
      Teleduino2560.setStatusLed(2, false, 10000);
      Teleduino2560.reset();
    }
  }
  else
  {
    Ethernet.begin(mac, deviceIp, dnsIp, gatewayIp, subnet);
  }
  delay(1000);

  Teleduino2560.setStatusLed(3); // Connect to server
  if((useDns && !Client.connect(serverName, serverPort)) || (!useDns && !Client.connect(serverIp, serverPort)))
  {
    Teleduino2560.setStatusLed(3, false, 10000);
    Teleduino2560.reset();
  }
  lastInstruction = millis();
}

void loop()
{
  if(Client.connected())
  {
    // What we need to do depends on which 'stage' we are at
    switch(stage)
    {
      case 0: // Wait for start byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage++;
          }
        }
        break;
      case 1: // Reset variables
        dataLength = 0;
        hexStage = 0;
        stage++;
        break;
      case 2: // Instruction byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            stage = 0;
            break;
          }
          if(!hexStage)
          {
            data[0] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[0] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            stage++;
          }
        }
        break;
      case 3: // Data length byte
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            stage = 0;
            break;
          }
          if(!hexStage)
          {
            data[1] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[1] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            stage++;
          }
        }
        break;
      case 4: // Data
        if(Client.available())
        {
          char c = Client.read();
          if(c == '?')
          {
            stage = 1;
            break;
          }
          else if(c == '\r' || c == '\n' || c == '.')
          {
            if(dataLength == data[1])
            {
              stage++;
              break;
            }
            else
            {
              stage = 0;
              break;
            }
          }
          if(!hexStage)
          {
            data[2 + dataLength] = Teleduino2560.hexDecode(c) * 16;
          }
          else
          {
            data[2 + dataLength] += Teleduino2560.hexDecode(c);
          }
          hexStage = !hexStage;
          if(!hexStage)
          {
            dataLength++;
          }
        }
        break;
      case 5: // Execute instruction and return result
        Teleduino2560.instruction(data);
        Client.write('!');
        for(int i = 0; i < data[1] + 2; i++)
        {
          Client.write(Teleduino2560.hexEncode(data[i] / 16));
          Client.write(Teleduino2560.hexEncode(data[i] % 16));
        }
        Client.write('\n');
        lastInstruction = millis();
        stage = 0;
        break;
    }
  }
  else
  {
    Teleduino2560.setStatusLed(10);
    Teleduino2560.reset();
  }

  // Has the instruction timeout been reached?
  if(millis() - lastInstruction > 30000)
  {
    Client.flush();
    Client.stop();
    Teleduino2560.setStatusLed(9);
    Teleduino2560.reset();
  }

  // Process refreshes every 50ms
  if(millis() - lastRefresh >= 50)
  {
    Teleduino2560.pinTimers();
    Teleduino2560.shiftRegisterTimers();
    Teleduino2560.shiftRegisters();
    lastRefresh = millis();
  }

  // Check to see if reset has been requested
  Teleduino2560.checkReset();
}


But when I do so the LCD loses track and shows a single random character all over the screen. The Teleduino library works well though and I can access the Arduino vía Teleduino server and to use several commands.

alexokaban

Hi.

I finally found what was wrong. It was an issue due to the usage that the Ethernet Shield gives to some of the Arduino pins. It seems that I was using pins that this shield uses too. I found the solution at this project page, down at one of its comments:

Arduino Project: HTML to LCD

Quote
by Ronny:

I saw gibberish on the screen. The solution was to change the pins used by the LCD:
LiquidCrystal lcd(9, 8, 7, 6, 5, 3);

* Ethernet shield using pins rx ,tx and digital pins 10,11,12,13.
* So we don't select these pins for the LCD connection.
* Thus we select digital pins 9,8,7,6,5,4 of Arduino for LCD connection.

Go Up