Go Down

Topic: no known conversion from String to const char* error (Read 141 times) previous topic - next topic

arduidiot

Apr 08, 2015, 11:42 pm Last Edit: Apr 08, 2015, 11:43 pm by arduidiot
ive attached the pde, .ino & the verbose, i have the uno talking back to my processing sketch no problem when i put a constant character as an argument for the Serial.write line,  but when i ask it to write back the bytes received for each new line, it tells me i cant convert a string to a constant char.

and i just started to get a  idea what to do about this but ill post anyway and update the post if it works,

 i was thinking store all the serial data read for the line as an int array( ascii code for keyboard input)   and have the processing sketch do the conversion to a string and print the line as opposed to the uno converting it.
im a good observer. not the brightest but very curious.

that poor innocent dog died from AC. he died.

I do not refuse my dinner simply because I do not understand the process of digestion."

UKHeliBob

Please do us all a favour and paste your files here instead of attaching them which means they have to be downloaded.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulS

Quote
it tells me i cant convert a string to a constant char.
No, it doesn't. It tells you that you can't convert a class instance to a const char*. So, why do you think that such a conversion should be possible? Can you convert an instance of the class LiquidCrystal to a const char *? Of course not. That makes no sense. Well, it makes no sense assuming that you can convert an instance of the String class to a const char *.

arduidiot

well ive half fixed it.

.INO CODE:

Code: [Select]
/*
  Serial Event example

 When new serial data arrives, this sketch adds it to a String.
 When a newline is received, the loop prints the string and
 clears it.

 A good test for this is to try it with a GPS receiver
 that sends out NMEA 0183 sentences.

 Created 9 May 2011
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/SerialEvent

 */
int LINE[200];
int k = 0;
String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {

    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {

  while (Serial.available()) {

    // get the new byte:
    char inChar = Serial.read();
    inputString += inChar;

    // add it to the inputString:

    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    {
      for (int i = 0; i <= inputString.length(); i++) {
        Serial.write(inputString.charAt(i));
        k = 0;
        stringComplete = true;



      }
    }
  }
}



PDE CODE:

Code: [Select]
/**
 * Serial Duplex
 * by Tom Igoe.
 *
 * Sends a byte out the serial port when you type a key
 * listens for bytes received, and displays their value.
 * This is just a quick application for testing serial data
 * in both directions.
 */


import processing.serial.*;

Serial myPort;      // The serial port
int whichKey = -1;  // Variable to hold keystoke values
int inByte = -1;    // Incoming serial data
String inputSINGLELINE;
String[] inputFULL;

void setup() {
  size(400, 300);
  // create a font with the third font available to the system:
 

  // List all the available serial ports:
  printArray(Serial.list());

  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // In Windows, this usually opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {

  background(0);
  char c = char(inByte);
  text("Last Received: " +c, 10, 130);
  text("Last Sent: " + inputSINGLELINE, 10, 100);
   text(Serial.list()[0], 10, 160);
}

void serialEvent(Serial myPort) {
 
 
}

void keyPressed() {
  // Send the keystroke out:
 
  whichKey = key;
  inputSINGLELINE+=whichKey;

myPort.write(inputSINGLELINE);
 
 if(keyCode==ENTER){inByte = myPort.read();inputSINGLELINE=null;}
}



i am just trying the uno to write back the line typed each time i press ENTER.
im a good observer. not the brightest but very curious.

that poor innocent dog died from AC. he died.

I do not refuse my dinner simply because I do not understand the process of digestion."

PaulS

Code: [Select]
        stringComplete = true;
The string (String, actually) is complete because it contains some data? I hardly think so.

Is there some reason to set stringComplete more than once?


Nick Gammon

#5
Apr 11, 2015, 12:23 am Last Edit: Apr 11, 2015, 12:23 am by Nick Gammon
Code: [Select]
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    {
      for (int i = 0; i <= inputString.length(); i++) {
        Serial.write(inputString.charAt(i));
        k = 0;
        stringComplete = true;
      }
    }


It's a little hard to know where to start. There is no test for a newline. Why write out the string a character at a time? You are processing one too many characters in your loop.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

PaulS

Quote
You are processing one too many characters in your loop.
Well, it IS necessary to deal with the NULL terminator...

Nick Gammon

You want him to do a Serial.write of the 0x00 character, is that it? Why?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

arduidiot

im just trying to establish basic communication with a keyboard and the TX RX of an arduino board (uno). i have it responding fine only the characters it sends back is not the same as the keyboard input that the mega328 acknowledges with leds lighting up respectively when the above ino is uploaded to an uno board and the pde or the exported java app is run. ill just check if the exe build is success actually i remember having alot of my pdes getting null pointers
im a good observer. not the brightest but very curious.

that poor innocent dog died from AC. he died.

I do not refuse my dinner simply because I do not understand the process of digestion."

arduidiot

im a good observer. not the brightest but very curious.

that poor innocent dog died from AC. he died.

I do not refuse my dinner simply because I do not understand the process of digestion."

arduidiot

the .ino is a basic alteration of one of the examples by Tom I cant remember last name but you guys know who i mean Ignoe? i know its ball park
im a good observer. not the brightest but very curious.

that poor innocent dog died from AC. he died.

I do not refuse my dinner simply because I do not understand the process of digestion."

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy