雖然『小樹林系統』韌體已有新的版本︰
GrovePi/Firmware/Source/v1.2/grove_pi_v1_2_6/grove_pi_v1_2_6.ino
,初步考察
# 主設定 void setup() { // Serial.begin(38400); // start serial for output Wire.begin(SLAVE_ADDRESS); Wire.onReceive(receiveData); Wire.onRequest(sendData); # 二‧八問題主因,需要 // attachInterrupt(0,readPulseDust,CHANGE); } # cmd buffer 仍會越界 void receiveData(int byteCount) { while(Wire.available()) { if(Wire.available()==4) { flag=0; index=0; run_once=1; } cmd[index++] = Wire.read(); } } // callback for sending data void sendData() { if(cmd[0] == 1) Wire.write(val); if(cmd[0] == 3 || cmd[0] == 7 || cmd[0] == 56) Wire.write(b, 3); if(cmd[0] == 8 || cmd[0] == 20) Wire.write(b, 4); if(cmd[0] == 30) Wire.write(b, 9); if(cmd[0] == 40) Wire.write(dht_b, 9); if(cmd[0]==21) { Wire.write(b,21); b[0]=0; } if(cmd[0]==dust_sensor_read_cmd) { Wire.write(b,4); dust_latest=0; cmd[0]=0; } if(cmd[0]==encoder_read_cmd) { Wire.write(enc_val,2); enc_val[0]=0; cmd[0]=0; } if(cmd[0]==flow_read_cmd) { Wire.write(flow_val,3); flow_val[0]=0; cmd[0]=0; } }
,看來老問題依舊!!故不急於更新也。
實測驗證結果如下︰
pi@raspberrypi ~
pi@raspberrypi ~
pi@raspberrypi ~ i2cdetect -y 3 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- 05 -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- -- pi@raspberrypi ~ python Python 2.7.9 (default, Mar 8 2015, 00:52:26) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import grovepi >>> addr = 0x05 >>> grovepi.debugEnable() >>> potentiometer = 0 >>> grovepi.pinMode(potentiometer,"INPUT") 1 >>> grovepi.analogRead(potentiometer) 0 [11, 2, 195, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] 707 >>> ultrasonic_ranger = 2 >>> grovepi.ultrasonicRead(ultrasonic_ranger) 0 [11, 0, 225, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] 225 >>> grovepi.ultrasonicRead(ultrasonic_ranger) 0 [11, 0, 225, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] 225 >>> power=7 >>> grovepi.pinMode(power,"OUTPUT") 1 >>> grovepi.digitalWrite(power,1) 1 >>> grovepi.digitalWrite(power,0) 1 >>> grovepi.bus.write_i2c_block_data(5, 1, [3] + [0, 0, 0]) >>> grovepi.bus.read_i2c_block_data(5, 1) [11, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.bus.write_i2c_block_data(5, 1, [3] + [0, 0, 0]) >>> grovepi.read_i2c_byte(addr) 0 >>> grovepi.bus.read_i2c_block_data(5, 1) [11, 2, 195, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.read_i2c_byte(addr) 0 >>> grovepi.read_i2c_block(addr) [11, 2, 195, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.read_i2c_block(addr) [11, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.read_i2c_block(addr) [11, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.read_i2c_block(addr) [11, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>> grovepi.read_i2c_block(addr) [11, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] >>>
pi@raspberrypi ~ cat /dev/ttyUSB0 CMD = 254, index = 4 CMD = 5, index = 4 CMD = 3, index = 4 DATA = 0, 2, 195 CMD = 3, index = 0 CMD = 7, index = 4 DATA = 0, 0, 225 CMD = 7, index = 0 CMD = 7, index = 4 DATA = 0, 0, 225 CMD = 7, index = 0 CMD = 5, index = 4 CMD = 2, index = 4 CMD = 2, index = 4 CMD = 3, index = 4 CMD = 3, index = 0 CMD = 3, index = 4 DATA = 0, 2, 195 CMD = 3, index = 0 DATA = 0, 2, 195 CMD = 1, index = 1 CMD = 1, index = 2 CMD = 1, index = 3 CMD = 1, index = 4 CMD = 1, index = 0
想來樹莓派 3 之硬體 I2C 的『□ ○』一點也沒『改變』的耶??
※ 上天的使者
環山該有美,內湖應慈悲。
芳齡止四歲!奈何逐夢歸?