Welcome! Log In Create A New Profile

Advanced

Sending Message to LCD screen

Posted by tonypan 
Sending Message to LCD screen
October 18, 2018 01:10PM
I am having trouble sending messages from the printer to the RAMP LCD screen. The code I am writing is on Marlin-1.1.x. I would like to read an Analog input from an Arduino port, and send that information to the LCD screen. Where should I modify code to do so?
Re: Sending Message to LCD screen
October 18, 2018 02:31PM
Try M117 - Set LCD Message

;Put printing message on LCD screen
M117 My Print...


Computer Programmer / Electronics Technician
Re: Sending Message to LCD screen
October 18, 2018 07:09PM
Thank you so much for your response!

I could send screen messages with M117 commands on Pronterface. However, I would like to constantly read directly from an analog port on Arduino and create a feedback loop to send updates to the LCD screen. Maybe I am not understanding how to use gcode in Marlin correctly. Would you please be more specific about how and where to implement M117 to accomplish this task? I was thinking about declaring inline void gcode_M117() in Marlin_main.cpp and proceed from there. Am I on the right track? Thanks again!
Re: Sending Message to LCD screen
October 19, 2018 04:29AM
Marlin's G-Codes

[marlinfw.org]


Computer Programmer / Electronics Technician
Re: Sending Message to LCD screen
October 19, 2018 04:58AM
M117 calls lcd_setstatus(parser.string_arg); This puts what ever you want on the last line of the display.

so all you need to do is add something like the above to the main loop in Marlin_main.cpp and pass it the analog port
eg just before the idle() change it to

  lcd_setstatus(analogRead(ANALOG_PIN_YOU_WANT_TO_READ));
  idle();


Nb this is just hack.. if the controlling software sends a M117 it will over write this, till the next loop
and the code should have checks, to make sure you have a lcd defined and such things...

Also I have no idea how much of an impact this will have on the controller, could make it crawl and be unusable.

Edited 1 time(s). Last edit at 10/19/2018 05:00AM by Dust.
Re: Sending Message to LCD screen
October 19, 2018 09:54AM
Thanks for the advice, I have tried lcd_setstatus, but have some trouble with set_status.

It works if I just pass in a cstring directly, but I can't get it to work with floats or doubles. Is there a way to print out a float or double with lcd_setstatus? Here's what I have:
int sensorValue = analogRead(MFC_SENSOR);
double voltage = sensorValue * (5.0 / 1023.0);
char message[25] = "Voltage: ";
sprintf(message, "%f", voltage);
lcd_setstatus(PSTR(message));

I really appreciate your help!
Re: Sending Message to LCD screen
October 19, 2018 02:05PM
Furthermore, if I just say lcd_setstatus("string"), the last line of the LCD screen becomes blank and doesn't output the message properly.
Re: Sending Message to LCD screen
October 19, 2018 09:33PM
currently I have

  endstops.event_handler();
  lcd_setstatus("I am a fish");
  idle();

and my printer thinks is a fish, without any issues
Re: Sending Message to LCD screen
October 19, 2018 10:18PM
Looking at your code, there are some issues.... mostly with sprintf, It over writes message, and doesnt convert the %f correctly.

  int sensorValue = analogRead(MFC_SENSOR);
  char message[25]; 
  char voltagechararray[6+2]; 
  double voltage = sensorValue * (5.0 / 1023.0);
  dtostrf(voltage, 6, 2, voltagechararray); 
  sprintf(message, "Voltage: %s", voltagechararray); 
  lcd_setstatus(message);

works for me...

Edited 1 time(s). Last edit at 10/19/2018 11:23PM by Dust.
Re: Sending Message to LCD screen
October 23, 2018 10:30AM
Thanks again for your help!

It works on my RAMP now, except the setstatus is being called too frequently in the loop() and is updating the lcd screen too frequently, affecting the thermal manager reading as well. Is there a way to call setstatus less frequently, like once every second periodically?

Edited 1 time(s). Last edit at 10/23/2018 03:34PM by tonypan.
Re: Sending Message to LCD screen
October 23, 2018 09:47PM
look into the blink without using delay example [www.arduino.cc]

wrap this delay around your function.
Re: Sending Message to LCD screen
October 25, 2018 10:55AM
Quote
Roberts_Clif
Marlin's G-Codes

[marlinfw.org]

Hello
I think there are at least two matters: When you place the strings in M117, but you are running G0 and M0, the M117 doesn't work. Is there any way to put message when you use G0 and M0?
Sorry, only registered users may post in this forum.

Click here to login