hallo,
I have a basic problem using the rx/tx connectors of arduino boards nano and uno.
my project: because, after connecting a 2.8" display only less ports are free for input/output I want to connect a nano via rx/tx to the uno-board using this to show the values.
this seems to be easy but I have no success.
I´m searching a most simple code to implement to my other program parts.
and it should run over the rx/tx tx/rx pins ..... dont know why they are described so...and not useable?
I won´t show my codes...I know they are not korrekt.
I´m virtuoso in serial communication with basic-language... but not with C
but that seems not to be the problem.
there are any charakters appearing on the screen. but I dont know where these are received from.
the NANO works perfect and I get korrekt values on the serial monitor.
these values should appear on the UNO-display.
my questions: must tx/rx pins be aktivated? like this: pinMode(...., OUTPUT); ?
what date-format do the transmitted data have? o.k. they are digital... ? start/stop-bit?
how many data-bits? must I take my osci first?
and how must the UNO read them.... as a string? or single char-value.
I tried everything....no satisfying effect... always the same numbers...without sens. the whole ASCII- code-table...may be . it is possible that the nano doesn´t send on TX. but the values appear on the serial monitor as I discribed above... but I want to see them at the 2.8" display.
how can I get tft.println(values) ?
thank you trying to help me
ps
osci says: data are flowing from NANO. 1 start-bit 48 data-bit? 5 char and CR?
now I have an idee: may it be serial receiving is unable if usb is connected with the PC? fact is: USB doesn´t work if TxD is connected with the NANO ???????
no...it´s not silly.
I will send code, as soon as possible.
first I must do it by myself. I now know: the NANO is sending data without problems. further I can receive these data as CHAR.... but only one by one
I can´t find any example what a char is... is it to treat like a string? it seems do be restistant.
it will work if I exactly know how to create length of data( buffer-size) string-length or such as.....
and buffer must be cleared... there are always the same data in char...until reset....
to night I see more.
then if the first NUMERIC-value appears on my 2.8" screen... I send both codes (NANO and UNO) an you can correct it please.
stern:
further I can receive these data as CHAR.... but only one by one
I can´t find any example what a char is... is it to treat like a string? it seems do be restistant.
If we can see your code it makes it much easier to understand your thinking and then to explain things.
Technically, a char is a signed 8 bit value, whereas a byte is an unsigned 8 bit value. A string is an array of chars terminated with a char having a value of 0.
However I won't be surprised to hear that is not answering the real question in your mind.
this is the actually used code on the UNO with display:
// UNO
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com
// freie pins: A3 A5 D10 11 12 13
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
//char d1,d2,d3,d4;
char dat=0;
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
Serial.println(F("Using Adafruit 2.4\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Adafruit 2.4\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
}else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if(identifier==0x0101)
{
identifier=0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
}else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier=0x9341;
}
tft.begin(identifier);
}
void loop(void) {
if (Serial.available() > 0) {
dat= Serial.read();
}
//zeitformatierung
int time=millis()/1000;
int stime=time;
int mtime=time/60;
int htime=time/3600;
int dtime=time/3600*24;
stime=stime-mtime*60;
mtime=mtime-htime*60;
htime=htime-dtime*24;7;
String sti = String(stime);
String mti = String(mtime);
String hti = String(htime);
tft.fillScreen(BLACK);
unsigned long start = micros();
uint16_t identifier = tft.readID();
tft.setCursor(50,30);
tft.setTextColor(BLUE); tft.setTextSize(1);
tft.println("490323 20160516");
tft.println("shield identfizierung:"),
tft.println(identifier,HEX);
tft.setTextColor(GREEN); tft.setTextSize(2);
tft.println("anfang");
tft.println(0);
tft.print("zeit "+ hti+":"+ mti+ ":"+sti);
tft.println();
tft.println();
tft.setTextColor(BLUE); tft.setTextSize(2);
tft.println("uno 2.8inch ");
tft.println("daten seriell in");
tft.setCursor(1,180);
tft.println("volt ");
Serial.println(dat);
tft.println(dat);
tft.setTextColor(WHITE); tft.setTextSize(2);
tft.println("test grundprogramm");
tft.setTextColor(YELLOW); tft.setTextSize(5);
tft.println("");
tft.setTextColor(RED); tft.setTextSize(1);
tft.println("ende");
tft.println();
delay(1000);delay(1000);delay(1000);delay(1000);delay(1000);
}
[Code/]
/*
NANO
lademanager solar-akku-wandler lsaw c20160505- wb49
panel-spannung messen analog A2
akku-spannung messen analog A3
ssr (akku-hauptschalter) schalten D2
serielle schnittstelle öffnen
werte verarbeiten
bedingung für digitale ausgabe (if ..else)
digitale ausgabe als leuchtende LED
ausgabe des anlog eingelesenen wertes durch den seriellen monitor
*/
// setup des programmes
void setup() {
#define adf 0.004882
// initialize digital pin 13 and 3 as an output.
pinMode(13, OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT); // ssr ansteuern
// öffnen der seriellen schnittstelle
Serial.begin(9600);
//ad-wandlung faktor
}
// programm schleife
void loop() {
//float adf= 5.0/1024.0*10;
//up panelspannung
//ua akkuspannung
float up = analogRead(A2);
float ua = analogRead(A3);
float U1 = up*adf;
float U2 = ua*adf*10;
//Serial.println(U1 );
Serial.print(U2 );
// bedingungen für das schalten des ssr
// z.b. u1>u2 ssr einschalten
// da nach einschalten des ssr u1=u2
// ausschalten des ssr wenn u1=u2< 36V
if (U2 < 25.5 )
{
digitalWrite(13, LOW);
}
else if (U2 >41.2)
{
digitalWrite(13, HIGH);
}
delay(500);
// wait for a second
}
[Code/]
I only want to show the measured values at the display .........
@stern, please modify your posts and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.
/* .... [Code/]
I´m looking 1/4 h for any "code-button"
programers must be think: everyone can , not all, but anything.... but not everyone thinks like a programer ;)
stern:
I always used this quick-reply-window.....
there is no </>
In my QuickReply window the </> is the first ICON on the left.
Maybe it is because I always edit in Source mode (the icon on the right). You can make this choice in your Profile. It makes posting links much easier.
now I have a rough but right working code. I hope you can see, what I mean.
/*
NANO
lademanager solar-akku-wandler lsaw c20160505- wb49
panel-spannung messen analog A2
akku-spannung messen analog A3
ssr (akku-hauptschalter) schalten D2
serielle schnittstelle öffnen
werte verarbeiten
bedingung für digitale ausgabe (if ..else)
digitale ausgabe als leuchtende LED
ausgabe des anlog eingelesenen wertes durch den seriellen monitor
*/
// setup des programmes
void setup() {
#define adf 0.004882
// initialize digital pin 13 and 3 as an output.
pinMode(13, OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT); // ssr ansteuern
// öffnen der seriellen schnittstelle
Serial.begin(9600);
//ad-wandlung faktor
}
// programm schleife
void loop() {
//float adf= 5.0/1024.0*10;
//up panelspannung
//ua akkuspannung
float up = analogRead(A2);
float ua = analogRead(A3);
float U1 = up*adf;
float U2 = ua*adf*10;
//Serial.println(U1 );
Serial.print(U2 );
Serial.print("|");
// bedingungen für das schalten des ssr
// z.b. u1>u2 ssr einschalten
// da nach einschalten des ssr u1=u2
// ausschalten des ssr wenn u1=u2< 36V
if (U2 < 25.5 )
{
digitalWrite(13, LOW);
}
else if (U2 >41.2)
{
digitalWrite(13, HIGH);
}
delay(500);
// wait for a second
}
// UNO
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com
// freie pins: A3 A5 D10 11 12 13
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
//char d1,d2,d3,d4;
char dat[10];
String buf;
int lang;
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
Serial.println(F("Using Adafruit 2.4\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Adafruit 2.4\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
}else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if(identifier==0x0101)
{
identifier=0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
}else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier=0x9341;
}
tft.begin(identifier);
}
void loop(void) {
buf="";
if (Serial.available()) {
int len=Serial.available();
for (int i=0;i<len;i++){
buf += (char)Serial.read();
}
}
//zeitformatierung
int time=millis()/1000;
int stime=time;
int mtime=time/60;
int htime=time/3600;
int dtime=time/3600*24;
stime=stime-mtime*60;
mtime=mtime-htime*60;
htime=htime-dtime*24;
String sti = String(stime);
String mti = String(mtime);
String hti = String(htime);
tft.fillScreen(BLACK);
unsigned long start = micros();
uint16_t identifier = tft.readID();
tft.setCursor(50,30);
tft.setTextColor(BLUE); tft.setTextSize(1);
tft.println("490323 20160516");
tft.println("shield identfizierung:"),
tft.println(identifier,HEX);
tft.setTextColor(GREEN); tft.setTextSize(2);
tft.println("anfang");
tft.println(0);
tft.print("zeit "+ hti+":"+ mti+ ":"+sti);
tft.println();
tft.println();
tft.setTextColor(BLUE); tft.setTextSize(2);
tft.println("uno 2.8inch ");
tft.println("daten seriell in");
tft.setCursor(1,180);
tft.println("volt ");
//controlle am seriellen monitor
Serial.println(buf);
lang=buf.length();
Serial.println(lang);
// vorläufige version den messwert aus data zu separieren
// bis mir was besseres einfällt oder ich einen vorschlag erhalte. nach art basic: mid$
//separatorposition bestimmen
int pos=buf.indexOf('|');
//für seriellen monitor
Serial.println(pos);
//dies ist noch nicht so ganz das wahre..........aber erfüllt seinen zweck
buf.toCharArray(dat,pos+1);
Serial.println(dat);
//anzeige auf TFT
tft.setCursor(55,180);
tft.print(dat);
tft.println();
tft.setTextColor(WHITE); tft.setTextSize(2);
tft.println("test grundprogramm");
tft.setTextColor(YELLOW); tft.setTextSize(5);
tft.println("");
tft.setTextColor(RED); tft.setTextSize(1);
tft.println("ende");
tft.println();
delay(1000);delay(1000);delay(1000);delay(1000);delay(1000);
}