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

<p>You can read more about the specific G-code in the <a href="http://reprap.org/wiki/G-code#M105:_Get_Extruder_Temperature" rel="nofollow">RepRap wiki</a>.</p>

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

<p>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 <code>M105</code> command, waits for 100ms, then reads the response of the serial buffer and prints it on the screen. </p>

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

<pre><code>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)..."
ser_printer.write('M105\n')
time.sleep(0.1)  # Allow time for response
print "Temperature response from printer:"
response = ser_printer.readline()
print response
</code></pre>

CC BY-SA 3.0
2016-07-25T00:52:19.347Z
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.
KDK
CC BY-SA 3.0
2016-07-25T08:59:49.933Z
I have edited the answer to include some basic information for connecting to the printer.
Demetris
CC BY-SA 3.0
2016-07-25T18:30:15.917Z
Thank you Demetris!  I worked with the piece of code you provided.  I am editing the question with the response I am getting.
KDK
CC BY-SA 3.0
2016-08-20T20:51:24.460Z
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.
KDK
CC BY-SA 3.0
2016-08-22T05:58:29.257Z
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.
Demetris
CC BY-SA 3.0
2016-07-24T22:27:28.327Z
2016-07-25T09:04:49.083Z
2016-07-25T09:04:49.083Z
Demetris
<p>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?</p>
<p>Edit: Response from printer:</p>
<pre><code>Connecting to printer...
Connection response from printer:
6R7�P)��h&gt;L�JO� � ��V�\��`�r��T �� SK�&lt;ʪ� �&gt;�Vw^<span class="math-container">$���|���R n�I, o�!����H&gt;�
                                                                          mx�}M#
                                                                                 �LYԣPh���^@ ��rp � TP�j�~1�� V6     6 � f� 6�k#���&amp;�H".��k K2���ek�(��&amp;��^K�k2����Ul�(� ���~N�ʈ*.�&gt;Z��k#d$</span>�����(� ��
��(� ��� v��
���
Asking for temperatures (M105)...
Temperature response from printer:
^CTraceback (most recent call last):
  File &quot;printer_files/serialaccess.py&quot;, line 15, in &lt;module&gt;
    response = ser_printer.readline()
  File &quot;/usr/lib/python2.7/dist-packages/serial/serialposix.py&quot;, line 446, in read
    ready,_,_ = select.select([self.fd],[],[], self._timeout)
KeyboardInterrupt
</code></pre>
<p>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.</p>

CC BY-SA 3.0
2016-07-25T19:58:54.267Z
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.
Tom van der Zanden
<extruder><heated-bed><nozzle>
Access Temperature sensor data of 3D printer via Serial connection
KDK
# Access Temperature sensor data of 3D printer via Serial connection

(Asked by: username_0 on 2016-07-24)

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>�
                                                                          mx�}M#
                                                                                 �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)
KeyboardInterrupt

```

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.

**Tags:** extruder, heated-bed, nozzle

> **Comments:**
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2016-07-24. Score: 3 | Accepted answer

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](http://reprap.org/wiki/G-code#M105:_Get_Extruder_Temperature).

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)..."
ser_printer.write('M105\n')
time.sleep(0.1)  # Allow time for response
print "Temperature response from printer:"
response = ser_printer.readline()
print response

```

> **Comments:**
> **username_0**: 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.  
> **username_2**: I have edited the answer to include some basic information for connecting to the printer.  
> **username_0**: Thank you username_2!  I worked with the piece of code you provided.  I am editing the question with the response I am getting.  
> **username_0**: 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.  
> **username_2**: 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.  

---

