Pages: 1 [2]   Go Down
Author Topic: Can't figure out how to endlessly feed text to arduino for display on LCD  (Read 1677 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8600
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is riddled with delays(), I count about 2.5 seconds for each invocation of getMsgText() during which time nothing is happening.

I don't know if that's the problem but it can't help. How often does the Android send messages?

______
Rob

 
Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8600
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What does meetAndroid.receive() do?

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is riddled with delays(), I count about 2.5 seconds for each invocation of getMsgText() during which time nothing is happening.

I don't know if that's the problem but it can't help.

I went in and tweaked the delays a little bit, but the ones that remain are to control the speed of the text appearing on the LCD and the speed of the scrolling.

Quote
How often does the Android send messages?

From what I can tell, it pops a new message up/over to the arduino whenever the meetAndroid.receive command is reached in the main loop on the Arduino side.

Quote
What does meetAndroid.receive() do?

This is how I believe it works:
When the android app (see Android code below) reaches the Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'z', oneMessage); statement, it makes one string (in this case it's a string, but it could be int, float, or whatever) available to the Arduino, by either loading it to the Arduino or by notifying the Arduino that it has a string ready and available (I'm not sure which), doing this via the meetAndroid.receive statement on the Arduino side.  Along with the string is sent a flag (in this case it's a 'z') which the meetAndroid.receive statement uses to trigger the registered function associated with that flag, which here is the getMsgText function.  The getMsagText function triggers, at some point executing the getString statement, which grabs the string and places it into the array msgText.  At some point within or at the end of these steps, the Amarino.sendDataToArduino of the Android app makes another string available (if there are more) to the Arduino and the cycle continues.

Java function that sends an array of strings to the Arduino one at a time:
Code:
    private void messagesToArduino(ArrayList<message> messagesToDisplay) {
    int numMsgs = messagesToDisplay.size();
    String oneMessage;
    for (int i = 0; i < numMsgs; i++) {
    oneMessage = messagesToDisplay.get(i).message;
Amarino.sendDataToArduino(this, DEVICE_ADDRESS, 'z', oneMessage);
    }
    }

Does this give you any ideas where it (or I) might be falling down?
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8600
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With a quick Google I can't find anything about registerFunction() so I'll assume that registerFunction() sets a callback function that is in turn called by receive().

If this is the case then the entire string receiving is under your control because you call receive() whenever you like.

And if that is the case there should be no problems.

One thing I don't get though is why the two parameters of getMsgText (flag and numOfValues) are never used, surely they have a purpose.

I would get rid of all the LCD stuff and see if you can print strings to the serial monitor.

Code:
void getMsgText(byte flag, byte numOfValues) {
 
    meetAndroid.getString(msgText);
serial.println (msgText);
meetAndroid.flush();  // don't know if this is needed
}

Can you point to some documentation on the meetAndroid stuff?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll give a try to the printing to the serial monitor without the LCD stuff.  The meetAndroid library can be found here:

http://amarino-toolkit.net/

There isn't a ton of documentation, just the files themselves and a few examples that are available when you load the library into the Arduino IDE.

More can be found here, but details are still a bit sparse:

http://www.amarino-toolkit.net/tl_files/doc/index.html

If this is the case then the entire string receiving is under your control because you call receive() whenever you like.  And if that is the case there should be no problems.

Yes, that's exactly what I've been thinking, yet I still have problems.

Quote
One thing I don't get though is why the two parameters of getMsgText (flag and numOfValues) are never used, surely they have a purpose.

With much of this new to me, I was even more confused by that than you.  But this is how it has been implemented in all of the examples I've found and it works for me (to the extent that it works), so I have it like that.  I'll take a look again at the library files.  I'm sure I've looked at that, but I've now been through the files so many times trying so many different things, it's all starting to become one big blur.

Thanks again for your ongoing help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having trouble getting to print to the serial monitor because the bluetooth needs to be connected simultaneously in order to feed the strings in.  On my Arduino Pro Mini, I have the bluetooth module connected to the six pins at the end of the board, which is the same place I connect my ftdi connector when I need to upload a pde file to the arduino.  It's usually an either/or situation.  The option was to create a second serial port with the SoftwareSerial, which I have tried, but I can't seem to get the settings and wiring right.

The current state, which isn't working, has the bluetooth plugged into the six pins at the end of the board, has the ftdi module connected to the computer via USB, and connects the ftdi to the arduino with three wires:  A0 to ftdi-TX, A2 to ftdi-RX, and GND to ftdi-GND.  The port settings for USB Com Port are - Baud: 9600, Data Bits: 8, Parity: None, Stop Bits: 1, Flow Ctrl: None.  The port settings for the bluetooth (which are working - Android is speaking to Arduino) are: Baud: 57600, Data Bits: 8, Parity: None, Stop Bits: 1, Flow Ctrl: Hardware.

So the problem seems to lie in how I'm trying to connect the Arduino to the PC via the FTDI/USB wired connection.

Here is the current code trying to read in with bluetooth and output to Serial Monitor:
Code:
#include <SoftwareSerial.h>
#include <MeetAndroid.h>

#define MAX_MSG_LENGTH   160
#define rxPin  A2
#define txPin  A0

MeetAndroid meetAndroid;

SoftwareSerial softSerial = SoftwareSerial(rxPin, txPin);

char msgText[MAX_MSG_LENGTH];

void setup() {
  Serial.begin(57600);

  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  softSerial.begin(9600);

  meetAndroid.registerFunction(getMsgText, 'z');
}

void loop() {
  meetAndroid.receive();
}

void getMsgText(byte flag, byte numOfValues) {
  meetAndroid.getString(msgText);
  softSerial.println (msgText);
}
Logged

nr Bundaberg, Australia
Online Online
Tesla Member
***
Karma: 129
Posts: 8600
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd try softSerial.println ("some string"); just to prove the serial link. And I doubt you have to set the pin modes, pretty sure .begin() will do that, but it won't do any harm.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: 1 [2]   Go Up
Jump to: