Go Down

Topic: Updating an existing sketch which was written before the Uno for the MKR1000 (Read 959 times) previous topic - next topic

doctorwho8

Hello!
(I haven't been here in a very long while.)
Anyway I have this particular sketch:
Code: [Select]

void setup()
{
  Serial.begin(9600);
  backlightOn();
}

void loop()

  selectLineOne();
  Serial.print(millis());
  selectLineTwo();
  Serial.print(millis()/2);
  delay(100);
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.write(0xFE);   //command flag
   Serial.write(128);    //position
   delay(100);
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.write(0xFE);   //command flag
   Serial.write(192);    //position
   delay(100);
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.write(0xFE);   //command flag
              Serial.write((position+128));    //position
}else if (position<32){Serial.write(0xFE);   //command flag
              Serial.write((position+48+128));    //position
} else { goTo(0); }
   delay(100);
}

void clearLCD(){
   Serial.write(0xFE);   //command flag
   Serial.write(0x01);   //clear command.
   delay(100);
}
void backlightOn(){  //turns on the backlight
    Serial.write(0x7C);   //command flag for backlight stuff
    Serial.write(157);    //light level.
   delay(100);
}
void backlightOff(){  //turns off the backlight
    Serial.write(0x7C);   //command flag for backlight stuff
    Serial.write(128);     //light level for off.
   delay(100);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.write(0xFE);
}


It compiles and runs for the Uno, but it was originally tried out on the one from 2009, which is this guy:
Arduino Duemilanove.

And it does seem to compile and run for the Arduino MKR1000 device.
Code: [Select]

void setup()
{
  Serial.begin(9600);
  backlightOn();
}

void loop()

  selectLineOne();
  Serial.print(millis());
  selectLineTwo();
  Serial.print(millis()/2);
  delay(100);
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.write(0xFE);   //command flag
   Serial.write(128);    //position
   delay(100);
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.write(0xFE);   //command flag
   Serial.write(192);    //position
   delay(100);
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.write(0xFE);   //command flag
              Serial.write((position+128));    //position
}else if (position<32){Serial.write(0xFE);   //command flag
              Serial.write((position+48+128));    //position
} else { goTo(0); }
   delay(100);
}

void clearLCD(){
   Serial.write(0xFE);   //command flag
   Serial.write(0x01);   //clear command.
   delay(100);
}
void backlightOn(){  //turns on the backlight
    Serial.write(0x7C);   //command flag for backlight stuff
    Serial.write(157);    //light level.
   delay(100);
}
void backlightOff(){  //turns off the backlight
    Serial.write(0x7C);   //command flag for backlight stuff
    Serial.write(128);     //light level for off.
   delay(100);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.write(0xFE);
}


Since the Uno and the Duemilanove both have the serial port at the 0 and 1 position and the MKR1000 repositioned the pins to 14 and 13, should it be possible to simply switch pin positions from the 1 position on the Uno to 13 position on the MKR1000?

Obligatory reference:
That original came from this page on main Arduino site:
Sparkfun LCD serial displays

Ideally I am leaning towards using the entire Sparkfun LCD serial display provide programming status from the MKR1000.

ballscrewbob

If I were you I would be looking at alternatives, IC2 etc as I always found serial displays to be a little sluggish and in some cases suffer from flicker.
Sparkfun 128x64 serial display sits unused here waiting for a project where it does not matter about the quirks.

Displays have come a little way from that article and it might be worth taking advantage of that IMHO.

Tend to jump on the Chinese bandwagon for displays too as in most cases they offer almost a 2 for the price of one when it comes to Sparkfun prices if you can forgive delivery times.



It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

doctorwho8

If I were you I would be looking at alternatives, IC2 etc as I always found serial displays to be a little sluggish and in some cases suffer from flicker.
Sparkfun 128x64 serial display sits unused here waiting for a project where it does not matter about the quirks.

Displays have come a little way from that article and it might be worth taking advantage of that IMHO.

Tend to jump on the Chinese bandwagon for displays too as in most cases they offer almost a 2 for the price of one when it comes to Sparkfun prices if you can forgive delivery times.

Hello!
Okay.
And in retrospect the method didn't work.
I see your point.

ballscrewbob

The other more common problem is discussed HERE

Certainly something to be aware of with 3.3 volt boards.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

doctorwho8

The other more common problem is discussed HERE

Certainly something to be aware of with 3.3 volt boards.
Hello!
An excellent point. I am used to 3,3v devices, in the shape a of the Pi family members, but I agree that in this shape it is indeed different. That is we are exploring a totally different universe here, than the one inhabited by the Pi.

Naturally I'll check to see if the same module is available in 3.3v style. That is they do sell a module who accepts serial formatted text and translates it into parallel form for regular LCD displays.

The only serial LCD module I know of who supports both 5v and 3,3v ones are from the Parallax company and are originally aimed to their own modules of course, but they state on their retail packaging that the thing will work for any device.

This is it, Parallax 2 x 16 Serial LCD (Backlit)]

That's their original product page, of course the sketch code fragments which contain instructions to turn on or turn off the backlight would need to be written to make use of the code one Parallax chose.

Go Up