I want to access the bed and nozzle temperature sensor data of a 3D printer via serial connection. Could someone please guide me in the right direction?


Edit: Response from printer:

Connecting to printer...
Connection response from printer:
6R7�P)��h>L�JO� � ��V�\��`�r��T �� SK�<ʪ� �>�Vw^$���|���R n�I, o�!����H>�
                                                                                 �LYԣPh���^@ ��rp � TP�j�~1�� V6     6 � f� 6�k#���&�H".��k K2���ek�(��&��^K�k2����Ul�(� ���~N�ʈ*.�>Z��k#d$�����(� ��
��(� ��� v��
Asking for temperatures (M105)...
Temperature response from printer:
^CTraceback (most recent call last):
  File "printer_files/serialaccess.py", line 15, in <module>
    response = ser_printer.readline()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 446, in read
    ready,_,_ = select.select([self.fd],[],[], self._timeout)

After the code asks the printer for temperature values, there is no output on the terminal anymore. I waited for a while and then killed it using control+c. It is clear that the printer is responding to the connection response but I am not sure why it is not returning the temperature values. Again, thanks a lot for your help, Demetris!

  • 1
    $\begingroup$ This is veering into off-topic territory. This is not longer about the tools and applications of 3D printers, it's about programming and developing applications for one. $\endgroup$ Jul 25, 2016 at 19:58

1 Answer 1


Assuming your printer accepts conventional G-code flavor, extruder and bed temperature can be retrieved by sending M105 through the serial port. The printer will respond with ok T:XXX.X B:XXX.X where T is the nozzle temperature and B is the bed temperature.

You can read more about the specific G-code in the RepRap wiki.

EDIT: I am editing the answer to include information for connecting to the printer using a simple python script.

The following script, first opens a serial connection to the printer. For Marlin firmware, when you first connect to the printer, it needs some time to initialize and respond back. That is why some delay is needed before reading the response. After printing the response, the script sends the M105 command, waits for 100ms, then reads the response of the serial buffer and prints it on the screen.

Note /dev/ttyUSB0 is the serial port name and in your case it may be different. Also 250000 is the baud rate of the connection; 250000 is the default value of my printer so you need to replace this with the baud rate that your printer uses.

import serial
import time

ser_printer = serial.Serial('/dev/ttyUSB0', 250000)
print "Connecting to printer..."
time.sleep(30)  # Allow time for response
buffer_bytes = ser_printer.inWaiting()
response = ser_printer.read(buffer_bytes)  # Read data in the buffer
print "Connection response from printer:"
print response
print "Asking for temperatures (M105)..."
time.sleep(0.1)  # Allow time for response
print "Temperature response from printer:"
response = ser_printer.readline()
print response
  • $\begingroup$ Thank you for your prompt reply! I had read about the firmware commands in the RepRap wiki page. I am not really sure how to interface with the printer in order to send those commands. I am a beginner in this field. I really appreciate your help. $\endgroup$
    – KDK
    Jul 25, 2016 at 0:52
  • $\begingroup$ I have edited the answer to include some basic information for connecting to the printer. $\endgroup$
    – Demetris
    Jul 25, 2016 at 8:59
  • $\begingroup$ Thank you Demetris! I worked with the piece of code you provided. I am editing the question with the response I am getting. $\endgroup$
    – KDK
    Jul 25, 2016 at 18:30
  • $\begingroup$ I want to access the bed temperature of the 3D printer. I am able to get the temperatures using serial connection. The problem that I am facing now is that as soon as I give the command, I get the temperature values, however the print job stops. Is there a way around it? I want to get the temperature values as the print job goes on. $\endgroup$
    – KDK
    Aug 20, 2016 at 20:51
  • $\begingroup$ This seems to be a different problem. Please create a new question describing your problem in detail. This will help you answer your question much more efficiently. $\endgroup$
    – Demetris
    Aug 22, 2016 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .