Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python …缩进错误:未缩进与任何外部缩进级别不匹配”;_Python_Raspberry Pi3_Gpio - Fatal编程技术网

Python …缩进错误:未缩进与任何外部缩进级别不匹配”;

Python …缩进错误:未缩进与任何外部缩进级别不匹配”;,python,raspberry-pi3,gpio,Python,Raspberry Pi3,Gpio,这是我的代码…我的代码没有什么问题…识别线错误161。。。 例如,错误如下……第161行……缩进错误:未缩进与任何外部缩进级别不匹配” 帮助 帮助 帮助 导入系统 将RPi.GPIO导入为GPIO 导入操作系统 进口Adafruit_DHT 导入urllib2 导入smbus 导入时间 从ctypes导入c_short #注册地址 regCall=0xAA regMean=0xF4 regMSB=0xF6 regLSB=0xF7 regPres=0x34 regTemp=0x2e 调试=1 样本

这是我的代码…我的代码没有什么问题…识别线错误161。。。 例如,错误如下……第161行……缩进错误:未缩进与任何外部缩进级别不匹配”

帮助 帮助 帮助

导入系统 将RPi.GPIO导入为GPIO 导入操作系统 进口Adafruit_DHT 导入urllib2 导入smbus 导入时间 从ctypes导入c_short #注册地址 regCall=0xAA regMean=0xF4 regMSB=0xF6 regLSB=0xF7 regPres=0x34 regTemp=0x2e 调试=1 样本=2 deviceAdd=0x77 humi=“” temp=“” #总线=smbus.smbus(0)#对于Pi1使用0 I2cbus=smbus.smbus(1)#对于Pi2使用1 DHTpin=17 key=“30BCDSRQ52AOI3UA”#输入ThingSpeak中的写入API密钥 GPIO.setmode(GPIO.BCM) #定义GPIO到LCD的映射 LCD_RS=18 LCD_EN=23 LCD_D4=24 LCD_D5=16 LCD_D6=20 LCD_D7=21 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(液晶显示器、GPIO.OUT) GPIO.setup(液晶显示器、GPIO.OUT) GPIO.setup(LCD_D4,GPIO.OUT) GPIO.setup(LCD_D5,GPIO.OUT) GPIO.setup(LCD_D6,GPIO.OUT) GPIO.setup(LCD_D7,GPIO.OUT) def convert1(数据,i):#有符号16位值 返回c_short((数据[i]>12 X1=(B2*B62)>>11 X2=AC2*B6>>11 X3=X1+X2 B3=((AC1*4+X3)>2 X1=AC3*B6>>13 X2=(B1*B62)>>16 X3=((X1+X2)+2)>>2 B4=(AC4*(X3+32768))>>15 B7=(P1-B3)*(50000>>样本) P=(B7*2)/B4 X1=(P>>8)*(P>>8) X1=(X1*3038)>>16 X2=(-7357*P)>>16 压力=P+((X1+X2+3791)>>4) 返回(str(压力/100.0)) def readDHT(): humi,temp=Adafruit\u DHT.read\u retry(Adafruit\u DHT.DHT11,DHTpin) 返回(str(int(humi)),str(int(temp))) def lcd_init(): lcdcmd(0x33) lcdcmd(0x32) lcdcmd(0x06) lcdcmd(0x0C) lcdcmd(0x28) lcdcmd(0x01) 睡眠时间(0.0005) def lcdcmd(ch): GPIO.输出(RS,0) GPIO.输出(D4,0) GPIO.输出(D5,0) GPIO.输出(D6,0) GPIO.输出(D7,0) 如果ch&0x10==0x10: GPIO.输出(D4,1) 如果ch&0x20==0x20: GPIO.输出(D5,1) 如果ch&0x40==0x40: GPIO.输出(D6,1) 如果ch&0x80==0x80: GPIO.输出(D7,1) GPIO.输出(EN,1) 睡眠时间(0.0005) GPIO.输出(EN,0) #低位 GPIO.输出(D4,0) GPIO.输出(D5,0) GPIO.输出(D6,0) GPIO.输出(D7,0) 如果ch&0x01==0x01: GPIO.输出(LCD_D4,1) 如果ch&0x02==0x02: GPIO.输出(LCD_D5,1) 如果ch&0x04==0x04: GPIO.输出(LCD_D6,1) 如果ch&0x08==0x08: GPIO.输出(LCD_D7,1) GPIO.输出(EN,1) 睡眠时间(0.0005) GPIO.输出(EN,0) def lcddata(ch): GPIO.输出(RS,1) GPIO.输出(D4,0) GPIO.输出(D5,0) GPIO.输出(D6,0) GPIO.输出(D7,0) 如果ch&0x10==0x10: GPIO.输出(D4,1) 如果ch&0x20==0x20: GPIO.输出(D5,1) 如果ch&0x40==0x40: GPIO.输出(D6,1) 如果ch&0x80==0x80: GPIO.输出(D7,1) GPIO.输出(EN,1) 睡眠时间(0.0005) GPIO.输出(EN,0) #低位 GPIO.输出(D4,0) GPIO.输出(D5,0) GPIO.输出(D6,0) GPIO.输出(D7,0) 如果ch&0x01==0x01: GPIO.输出(LCD_D4,1) 如果ch&0x02==0x02: GPIO.输出(LCD_D5,1) 如果ch&0x04==0x04: GPIO.输出(LCD_D6,1) 如果ch&0x08==0x08: GPIO.输出(LCD_D7,1) GPIO.输出(EN,1) 睡眠时间(0.0005) GPIO.输出(EN,0) def液晶串(Str): l=0; l=len(Str) 对于范围(l)中的i: lcddata(作战需求文件(信息[i])) lcd_init() lcdcmd(0x01) 立法会("电路摘要") lcdcmd(0xc0) 立法会(欢迎你) 时间。睡眠(3)#3秒延迟 #main()函数 def main(): 打印“系统就绪…” URL='1〕https://api.thingspeak.com/update?api_key=%s“%key” 打印“等待…” 尽管如此: (呼米,温度)=readDHT() (压力)=读数BMP180() lcdcmd(0x01) 立法会("恒湿指数#温度#P#hPa)) LCD字符串(腐殖酸+'%'+%sC%s'%(温度、压力)) finalURL=URL+“&field1=%s&field2=%s”%(湿度、温度)+“&field3=%s”%(压力) 打印财务报表 s=urllib2.urlopen(finalURL); 打印humi+“”+温度+“”+压力 s、 关闭() 时间。睡眠(10) 如果名称=“\uuuuu main\uuuuuuuu”: main()
所以我复制并粘贴了您的代码,在第161行前面有一个额外的空间

def lcddata(ch): 
第203行

lcdcmd(0x01)
所有这些代码都有额外的标签,这是不应该的

def main():

print 'System Ready...'
URL = 'https://api.thingspeak.com/update?api_key=%s' % key
print "Wait...."
while True:
        (humi, temp)= readDHT()
        (pressure) =readBmp180()

        lcdcmd(0x01)
        lcdstring("Humi#Temp#P(hPa)")
        lcdstring(humi+'%'+"  %sC  %s" %(temp, pressure))
        finalURL = URL +"&field1=%s&field2=%s"%(humi, temp)+"&field3=%s" %(pressure) 
        print finalURL
        s=urllib2.urlopen(finalURL);
        print  humi+ " " + temp + " " + pressure
        s.close()
        time.sleep(10)

lcd_init()lcdcmd(0x01)lcdstring(“电路摘要”)
。下次请隔离行,而不是发布整个代码。您甚至不必在此处发布。您有两个不同的缩进级别…一个有2个空格,一个有制表符。前面还有一个额外的空格
lcdcmd(0x01)
还有Jean说的,你可能已经注意到了-Python对空格/缩进敏感。删除多余的空格并假装你从未将其发布到Stack Overflow。我建议你阅读Stackoverflow页面“如何提出一个好问题:欢迎Matthew!感谢您愿意提供帮助,但这里的用法并不是针对这些仅由简单打字错误引起的问题(特别是当有人在评论中已经注意到这一点时!)此外,这个问题已经一个月了,所以你的工作对OP有帮助的可能性很小。但是继续做好工作!
def main():

print 'System Ready...'
URL = 'https://api.thingspeak.com/update?api_key=%s' % key
print "Wait...."
while True:
        (humi, temp)= readDHT()
        (pressure) =readBmp180()

        lcdcmd(0x01)
        lcdstring("Humi#Temp#P(hPa)")
        lcdstring(humi+'%'+"  %sC  %s" %(temp, pressure))
        finalURL = URL +"&field1=%s&field2=%s"%(humi, temp)+"&field3=%s" %(pressure) 
        print finalURL
        s=urllib2.urlopen(finalURL);
        print  humi+ " " + temp + " " + pressure
        s.close()
        time.sleep(10)