Read the serial communication information from arduino with python.
Please write your question in detail here.
I want to receive information from COM3 using python's jupter notebook.
However, the following message does not work.
Where should I change it?
Applicable source code
ValueError Traceback (most recent call last) <ipython-input-1-d6ee45546a66>in<module>() 62 63 if __name__ == '__main__': --->64 main () <ipython-input-1-d6ee45546a66>in main () 28 29 --->30 xdeg = float (xdeg) 31 ydeg = float (ydeg) 32 # Update temperature data list ValueError: could not convert string to float: "'55"
import numpy as np import matplotlib.pyplot as plt import pygame from pygame.locals import * import serial import sys def main (): ser = serial.Serial ("COM3") # COM port (Arduino connection) xdegs =  * 100 # Store temperature ydegs =  * 100 # Store temperature t = np.arange (0,100,1) plt.ion () # Pygame settings pygame.init () # initialization screen = pygame.display.set_mode ((200, 200)) # Create screen (100 × 100) pygame.display.set_caption ("tilt angle") # title bar font = pygame.font.Font (None, 30) while True: data = ser.readline (). rstrip () # Read up to \ n (\ n removed data = str (data) .replace ('"', '') (xdeg, ydeg) = data.split (",") xdeg = xdeg.replace ('b', '') ydeg = ydeg.replace ('b', '') xdeg = float (xdeg) ydeg = float (ydeg) # Update temperature data list xdegs.pop (99) xdegs.insert (0, float (xdeg)) ydegs.pop (99) ydegs.insert (0, float (ydeg)) # Set graph display line, = plt.plot (t, xdegs, 'r-', label = "X-axis [deg]") # Y-axis update line, = plt.plot (t, ydegs, 'b-', label = "Y-axis [deg]") # Y-axis update line.set_ydata (xdegs) line.set_ydata (ydegs) plt.title ("Real-time inclination angle") plt.xlabel ("Time [s]") plt.ylabel ("Inclination angle [deg]") plt.legend ();plt.grid () plt.xlim ([1,100]);plt.ylim ([-90,90]) plt.draw ();plt.clf () # Pygame processing screen.fill ((0,0,0)) # clear screen text = font.render ("(X, Y) = (" + xdeg + "," + ydeg + ")", False, (255,255,255)) screen.blit (text, (10, 10)) # render, display position pygame.display.flip () # update screen to reflect changes # Pygame event processing for event in pygame.event.get (): # End processing when end button is pressed if event.type == QUIT: pygame.quit () ser.close () plt.close () sys.exit () if __name__ == '__main__': main ()
In python3, the letter b is included? When the character b is removed with the replace function, the symbol'remains.
I think that the number'55 is the information sent from arudino via serial communication.
Please provide more detailed information here.
Answer # 1
b'***'is a notation for REPL (interactive environment) and debugging that indicates that the data is bytes type.
data = str (data) .replace ('"', '')
is wrong and
str (data)does not convert
strtype. See below for details on operation.
4. Built-in types — Python 3.6.5 documentation #str
Is the intended conversion obtained with
- i want to turn on and off the arduino led by serial communication (character string)
- Android Studio to modify the color of Log information
- Arduino serial port data transfer to computer in python and save to excel form
- The entire process of debugging Android Studio 36 smali
- pycharm set python file template information process diagram
- Detailed Android Studio 36 installation process and AVD installation and operation steps
- i want to save the data created in unity (map release information and high score) on the android apk and run it on the actual de
- enter string with arduino serial monitor
- i want to process values sent from arduino in real time with python
- vba - in excel and arduino serial communication, how to graph if excel receives serially
- c # - serial communication between arduino and unity is not possible
- serial port - randomly extract serial information with arduino
- python → arduino i want to see the received value on the serial monitor in real time
- android - about the process that the button appears when you touch the date
- Android implements two ways to transfer information in music playback progress bar (in service and activity)
- serial communication with arduino is not possible with c # windows forms
- Analysis of the process of crawling the product information of the Jingdong website with the Python CSS selector
- arduino mega (with atmega1280) that can not see serial output of arduino mega in vscode
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved