Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: SoftwareSerial library with LCD on: March 09, 2014, 08:24:42 am
I am using an Attiny84 which leaves me 3 pins left. For what I am working on, this is great. If you want, you could buy an LCD with i2c interface backpack. Only uses 2 pins. http://arduino-info.wikispaces.com/LCD-Blue-I2C#v1
2  Using Arduino / Programming Questions / Re: SoftwareSerial library with LCD on: March 08, 2014, 07:55:11 am
Thanks. Setting the index back to 0 did the trick. I also re-wrote most of the code, making it simpler.

Code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

#define rxPin 2 // receive
#define txPin 3 // transmit

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);


void setup(){
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
   // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
 
  mySerial.begin(9600);
  mySerial.print("LCD Display...");
  lcd.print("Initializing...");
  delay(800);
  lcd.clear();
  lcd.print("Ready");
}

void loop()
{
  // when characters arrive over the serial port...
  if (mySerial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
       
    // clear the screen
    lcd.clear();
    // read all the available characters
    int index = 0;
 
    while (mySerial.available() > 0) {

      // display each character to the LCD
      if(index < 16){
     
          lcd.setCursor(index, 0);   
     
      }else{     
         if(index > 34){
           index = 0;
           
           lcd.setCursor(index, 0);
         }else{
           lcd.setCursor(index-16, 1);
         }
      }
     
      lcd.write(mySerial.read());
      delay(100);
      index++;
    }
   
   }
}
3  Using Arduino / Programming Questions / SoftwareSerial library with LCD on: March 06, 2014, 08:37:42 pm
Hi,

I am using the SoftwareSerial library to send message over Serial to a 2X16 LCD display.  In the below code, I send over 32 characters. The 1 - 16 characters go on the first line and 17-32 go on the 2nd line. This works fine when using the Arduino IDE serial monitor. I can send over server messages and the LCD is updated. My issue is when I send the data via usb using python or C# (.net or Raspberry Pi). The first 32 characters update the LCD, but then it stops updating. In both cases I am using while loops to send over the messages. Any help would be great

The bellow code is flashed on the an Atty84

Code:

/*
  LiquidCrystal Library - Serial Input
*/
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

#define rxPin 2 // receive
#define txPin 3 // transmit

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
char lineOne[16];
char lineTwo[16];

int maxChar = 32;
char inLineData[32]; // Allocate some space for the string - only 32 chars / 16 allowed per line
char inLineChar=-1; // Where to store the character read


void setup(){
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
   // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
 
  mySerial.begin(9600);
  mySerial.print("LCD Display...");
  lcd.print("Initializing...");
  delay(800);
  lcd.clear();
  lcd.print("Ready");
}

void loop()
{
  // when characters arrive over the serial port...
  if (mySerial.available()) {
    // wait a bit for the entire message to arrive
    delay(1000);     
   
    // read all the available characters
    byte index = 0;
    int readData;
    while (mySerial.available() > 0) {
     
      readData = mySerial.read(); // Read a character
                               
      inLineData[index] = readData; // Store it   
      // display each character to the LCD         
      if(index < 16){             
         lcd.setCursor(index, 0);   
         lcd.write(inLineData[index]);         
      }else{                             
          lcd.setCursor(index, 1);
          lcd.write(inLineData[index]);         
      }
       delay(100);
       
       if(index>15){
         
         delay(100);         
         lcd.setCursor(index - 16, 1);
         lcd.write(inLineData[index]);
       
       }   
     
      index++;
    }
    delay(2000);
    index = 0;
   
  }
 
}

Example loop in python
Code:

while 1:
     // output serial message
sleep(2)
4  Using Arduino / Programming Questions / Re: ATTiny84 and SerialSofware on: February 16, 2013, 12:51:02 pm
Erni - you rock! My pins were off by one.. thanks so much.

Also thanks to Paul. I appreciate all the help and guidance.
5  Using Arduino / Programming Questions / Re: ATTiny84 and SerialSofware on: February 16, 2013, 11:41:57 am
I've tried 9600 and 4800.
6  Using Arduino / Programming Questions / Re: ATTiny84 and SerialSofware on: February 16, 2013, 11:19:33 am
When are you intending to start using the correct function (print(), if you need another hint) to send ASCII data?

Oh, and what clock rate are you using with the ATTiny? Have you selected the correct speed on both ends? If you are using other than a 16MHz chip, the speeds won't be the same.

Thanks - starting using print as hinted  smiley, also set my clock speed to 8 MHz. I followed these instructions (http://hlt.media.mit.edu/?p=1695):

Code:
Configuring the ATtiny to run at 8 MHz (for SoftwareSerial support)

By default, the ATtiny’s run at 1 MHz (the setting used by the unmodified “ATtiny45″, etc. board menu items). You need to do an extra
step to configure the microcontroller to run at 8 MHz – necessary for use of the SoftwareSerial library. Once you have the microcontroller
connected, select the appropriate item from the Boards menu (e.g. “ATtiny45 (8 MHz)”). Then, run the “Burn Bootloader” command
from the Tools menu. This configures the fuse bits of the microcontroller so it runs at 8 MHz. Note that the fuse bits keep their value
until you explicitly change them, so you’ll only need to do this step once for each microcontroller. (Note this doesn’t actually burn a
bootloader onto the board; you’ll still need to upload new programs using an external programmer.)

Still no luck
7  Using Arduino / Programming Questions / Re: ATTiny84 and SerialSofware on: February 16, 2013, 09:53:12 am
I understand the docs and understand what you're saying. The issue isn't that I get SOME junk, I am saying when I send a char, it will print out to the serial monitor as 'ÿ'. So even if I use binary or ASCII, the result is the same.

So,

Code:
mySerial.write("Hello world");

shows in the serial monitor as 'ÿ'

Below is an example that shows that I a receiving data on the ATTiny84, and my serial monitor is receiving data:

Code:
#include <SoftwareSerial.h>

#define rxPin 1
#define txPin 2
#define ledPin 8

// set up a new serial port
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  // define pin modes for tx, rx, led pins:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.write("Hello World - SoftwareSerial");
}

void loop() {
  // listen for new serial coming in:
  if(mySerial.available()){
 
    char someChar = mySerial.read();
    // print out the character:
    mySerial.write(someChar);
    // toggle an LED just so you see the thing's alive. 
    // this LED will go on with every OTHER character received:
    toggle(ledPin);
   
  }
 
}

void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState);
  // if pinState = 0, set it to 1, and vice versa:
  delay(50);
  pinState = !pinState;
}

As you can see I am only toggling the led if I am receiving data on the ATTiny84. Once again, I get 'ÿ' in tbe serial monitor.
8  Using Arduino / Programming Questions / Re: ATTiny84 and SerialSofware on: February 16, 2013, 09:10:06 am
Use a binary method to send ASCII data. Novel idea. I wonder why it's not more common.

Hi Thanks for the help. - Can you provide an example?

Read and echo the first byte available in the buffer, even if there is nothing in the buffer == garbage.

I understand, Garbage in, garbage out. So if I send a char, e.g. 'n', val should = '110' (ASCII) and should print out to serial '110'. Is this correct? Or will val always equal garbage. I am learning, so I appricate all the 'dumb down' help I can get  smiley
9  Using Arduino / Programming Questions / ATTiny84 and SerialSofware on: February 16, 2013, 07:26:15 am
Hi,

I am using the SoftwareSerial library to communicate with my ATTiny84. I can see that I am able to send and receive data via the FTDI breakout. In the Serial Monitor, I am receiving "junk" and it seems I am sending "junk". I have set the baud rate to 300, but I don't think it is a speed issue. Any ideas?

Here is my code:

Code:
#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(rxPin,txPin); // pin 2 = TX, pin 3 = RX (unused)
int led = 0;
int GREEN = 7;
int val = 109;

void setup()
{
  mySerial.begin(300); // set up serial port for 300 baud
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(GREEN, OUTPUT);
  delay(500); // wait for display to boot up
}

void loop()
{
  val = mySerial.read();
  mySerial.println(val);
 
  mySerial.write("Hello, world!");
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
  
  if (val == 110) { // "n" = 110 in dec from ascii
    
    digitalWrite(GREEN, HIGH);   // turn the LED on (HIGH is the voltage level)
    
  }
  
}
Pages: [1]