import numpy as np import matplotlib.pyplot as plt import pygame from pygame.locals import * import spidev import sys import time def main(): spi = spidev.SpiDev() spi.open(0,0) x = [0]*1000 t = np.arange(0,1000,0,0.001) plt.ion() pygame.init() sreen = pygame.display.set_mode((200,200)) while true: data = spi.xfer2([0x68,0x00]) b = (data[0] * 256 + data[1]) & 0x3ff line = b.readline().rstrip() line = b.spit(",") x.pop(999) x.insert(0,float(x)) line, = plt.plot(t,x,"-r") line.set_ydata(x) plt.legend();plt.grid() plt.xlim([1,1000]);plt.ylim([0,500]) plt.draw(); plt.clf() screen.fill((0,0,0)) screen.blit(text, (10,10)) pygame.display.flip() for event in pygame.event.get(): if evet.type == QUIT: pygame.quit() spi.close() plt.close() sys.exit() if __name__ == '__main__': main() ``````ここに言語を入力 コード
エラー内容
Traceback (most recent call last):
File"/home/pi/5\07.py", line 61, in <module>
main()
File"/home/pi/5\07.py", line 33, in main
line = b.readline().rstrip()
AttributeError: 'int'object has no attribute 'readline'
MCP3002の信号をSPI通信にてRaspberry Pi3へ入力し、その値をリアルタイムでグラフ化したいと考えています。そのためのプログラムとしてArduinoからシリアル通信でRaspberry Piへ送っているプログラムを改良したのですが、上手くいきませんでした。
解決できずに行き詰っています。アドバイスよろしくお願いします。また、その他上記プログラムで改善点等あればよろしくお願いします。