标签: raspberry-pi

PYGame - ImportError:没有名为locals Raspberry Pi的模块

我有以下代码:

 #!/usr/bin/python
 # -*- coding: iso-8859-15 -*-

 import pygame, random
 from pygame.locals import *
 pygame.init()
 clock = pygame.time.Clock()

 and so on
Run Code Online (Sandbox Code Playgroud)

应用程序都显示正常,但是当我编译代码时,我收到以下错误:

 Traceback (most recent call last):
 File "fish.py", line 4, in <module>
import pygame, random
 File "/home/pi/pygame/pygame.py", line 2, in <module>
ImportError: No module named locals


------------------
(program exited with code: 1)
Press return to continue
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?我是Python和Linux的新手.

我做了以下事情:

 pi@raspberrypi:~$ sudo apt-get install python-pygame
 Reading package lists... Done
 Building dependency tree       
 Reading state information... Done
 python-pygame is already the newest …
Run Code Online (Sandbox Code Playgroud)

python pygame raspberry-pi

0
推荐指数
1
解决办法
1万
查看次数

Python中函数声明的语法错误

我正在尝试用Python编写一个简单的网络服务器,不幸的是,我正陷入让函数工作的简单障碍!

import os, socket

class serv:
    def __init__(self):
        self.host
        self.port = 'localhost', 58008
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.bind((self.host, self.port)

    def send(self, msg):
        self.conn.send(msg + end)

    def run(self):
        self.socket.listen(1)
        self.conn
        self.addr = self.socket.accept()
        send(self, msg="Hello, world")

S = serv()
S.run()
Run Code Online (Sandbox Code Playgroud)

此代码在函数调用send上给出以下错误:

File "server.py", line 10
def send(self, msg):
  ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

如果它有帮助(我确定它不会),我在使用Adafruit WebIDE的Raspberry Pi上做这个.

python function raspberry-pi

0
推荐指数
1
解决办法
7145
查看次数

Raspberry Pi:从Raspberry Pi卸载piJS

如何从Raspberry Pi卸载piJS(从cmd-line或删除文件)?

我无法删除它,因为它是用curl安装的,我无法取消我的Pi与pijs.io的链接.

我希望你能提供帮助.

debian uninstall raspberry-pi raspbian

0
推荐指数
1
解决办法
915
查看次数

尝试打开/写入文件时语法无效

最近,我使用Raspberry Pi安装了新的DS18B20温度传感器.它运作良好,我设法修改Adafruit学习系统中的程序,以便在通过键盘输入询问时获得温度.下一步,我正在尝试将温度读数写入文件中.整个代码是:

import os
import glob
import time
import sys

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = int(temp_string) / 1000.0
        return temp_c

def write_temp():
    localtime=time.asctime(time.localtime(time.time())
    f = open("my temp",'w')
    f.write(print localtime,read_temp())
    f.close()

while …
Run Code Online (Sandbox Code Playgroud)

python syntax file raspberry-pi

0
推荐指数
1
解决办法
2万
查看次数

OSError:[errno2]没有这样的文件或目录

我试图从pir传感器获取信号,将其传输到Web服务.当我运行此代码时

if Current_State==1 and Previous_State==0:
  # PIR is triggered
    output =  subprocess.check_output(["Current_State==1 and enter code herePrevious_State==0","18"]);
     print "  Motion detected!"
     # Tell the Pi to run our speech script and speak the words
     # motion dtected! - anything after the .sh will be read out.
    enter code here` matches = re.search("Current_State==1 and Previous_State==0", output)
     move = int(matches.group(1))
     resultm = client.service.retrieveMove(move)
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

**Traceback (most recent call last):
  File "pir_5.py", line 48, in <module>
    output =  subprocess.check_output(["Current_State==1 and Previous_State==0", "18"]);
  File "/usr/lib/python2.7/subprocess.py", …
Run Code Online (Sandbox Code Playgroud)

python raspberry-pi

0
推荐指数
1
解决办法
2866
查看次数

我可以使用戴尔笔记本电脑屏幕显示Raspberry Pi的HDMI输入

我有戴尔Inspiron 14R(N4110)笔记本电脑和戴尔Inspiron 15R(N5110)笔记本电脑.我可以使用其中任何一个来显示Raspberry Pi的输入吗?

hdmi raspberry-pi

0
推荐指数
1
解决办法
2万
查看次数

IBM Bluemix:设备已连接,但"IBMIoT:错误:连接被拒绝:未授权"消息不断弹出

我正在IBM Bluemix中试验IoT服务,在Coursera参加正在运行的MOOC.我已经设置了试用帐户并成功注册了一些设备.我正在使用Bluemix中的以下简单Node-RED流测试Bluemix和我的Raspberry Pi之间的连接:

Node-RED流@ Bluemix在此输入图像描述

其中normalalert是各个字符串的简单注入节点,该format message节点同样简单(返回msg,其中msg.payload = {'a' : {'indicator' : msg.payload}};,IBM IoT节点如下:

在此输入图像描述

senseWAT设备已注册并成功连接到Bluemix,从Watson IoT Platform仪表板可以看出:

在此输入图像描述

从Raspberry方面,我设置了以下简单流程来捕获Bluemix中发布的'命令'(normalalert):

Node-RED流@ Raspberry Pi在此输入图像描述

与所述all commands节点是如下:

在此输入图像描述

现在,虽然'命令' normalalert从Bluemix传递到我的Raspberry,但我继续收到主题错误消息,如下所示(注意时间戳):

在此输入图像描述

并在Node-RED控制台中记录类似的错误消息(每分钟一次):

Connection Error :: Error: Connection refused: Not authorized
9 Jun 19:41:19 - [error] IBMIoT: Error: Connection refused: Not authorized
Iotfclient is offline. Retrying connection
Connection was closed.
Run Code Online (Sandbox Code Playgroud)

我想知道如何有可能,一方面让'命令'通过,另一方面得到每分钟错误信息声称我没有连接,因为我的设备未经授权.

有任何想法吗? …

raspberry-pi node-red watson-iot ibm-cloud

0
推荐指数
1
解决办法
2525
查看次数

C在终止时执行`system("do thing here")`

我一直试图摆脱示例代码并在Google上查找"C退出函数"来实现这一点但我在编译时总会遇到错误.在我的代码中,我使用它在代码启动时将环绕声从通道1转换为2.

{
   system("irsend SEND_ONCE newremote KEY_2 && gpio mode 6 output && gpio write 6 1");
}
Run Code Online (Sandbox Code Playgroud)

现在我想为它发送相同的命令,而是KEY_1gpio write 6 0当程序被终止切换我的音频回主输入.

main.c: In function ‘functionA’: main.c:276:5: warning: ‘main’ is normally a non-static function [-Wmain]
  int main( int argc, char **argv )
 ^~~~
main.c:327:1: error: expected declaration or statement at end of input  }  ^ 
At top level: main.c:276:5: warning: ‘main’ defined but not used [-Wunused-function]
  int main( int argc, char **argv )
 ^~~~
makefile:9: recipe for …
Run Code Online (Sandbox Code Playgroud)

c exit raspberry-pi

0
推荐指数
1
解决办法
78
查看次数

我可以在树莓派上同时运行多少个py脚本?

我知道您可以使用不同的终端运行多个脚本,但是必须有一个限制。我不能只在一个小圆周上跑一百万。所以真正的问题是...有没有办法检查我的脚本的要求。先感谢您!

pi零瓦特/ python 3

python raspberry-pi

0
推荐指数
1
解决办法
91
查看次数

如何使用多核而不是多线程进行编程?

我正在研究一个项目(硬件:RaspberryPI 3B +),该项目具有大量的计算和并行处理。目前,我注意到代码性能有些滞后。因此,我一直在寻找有效的方法来改善代码及其性能。

目前,我正在使用C语言(因为我可以轻松地访问和操作较低级别的驱动程序)并开发自己的一组函数,库和驱动程序,其运行速度比任何其他预定义或现成的库或插件都要快。

现在,我想使用单独的内核来执行相应的任务,而不是基于软件的多线程读取(Pthread)。那么,关于如何使用RaspberryPI的不同核心的任何建议或指南?

此外,如何检查CPU使用率以选择最佳内核来执行特定任务?

致谢,阿提夫·谢赫(Aatif Shaikh)

c++ multithreading raspberry-pi

0
推荐指数
1
解决办法
108
查看次数