Skip to content

Commit

Permalink
added and adjusted delays necessary for reliable operation on the Pi 3
Browse files Browse the repository at this point in the history
  • Loading branch information
pdg137 committed Jan 20, 2017
1 parent a4f5ff6 commit ebacaba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/AStarRPiSlaveDemo/AStarRPiSlaveDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Data
char notes[14];
};

PololuRPiSlave<struct Data,0> slave;
PololuRPiSlave<struct Data,5> slave;
PololuBuzzer buzzer;
AStar32U4Motors motors;
AStar32U4ButtonA buttonA;
Expand Down
7 changes: 7 additions & 0 deletions pi/a_star.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Pololu Corporation. For more information, see https://www.pololu.com/
import smbus
import struct
import time

class AStar(object):
def __init__(self):
Expand All @@ -13,8 +14,12 @@ def read_unpack(self, address, size, format):
# since the STOP interrupt will occasionally happen after the START
# condition, and the TWI module is disabled until the interrupt can
# be processed.
#
# A delay of 0.0001 (100 us) after each write is enough to account
# for the worst-case situation in our example code.

self.bus.write_byte(20,address)
time.sleep(0.0001)
byte_list = []
for n in range(0,size):
byte_list.append(self.bus.read_byte(20))
Expand All @@ -23,6 +28,7 @@ def read_unpack(self, address, size, format):
def write_pack(self, address, format, *data):
data_array = map(ord, list(struct.pack(format, *data)))
self.bus.write_i2c_block_data(20, address, data_array)
time.sleep(0.0001)

def leds(self, red, yellow, green):
self.write_pack(0, 'BBB', red, yellow, green)
Expand All @@ -47,3 +53,4 @@ def test_read8(self):

def test_write8(self):
self.bus.write_i2c_block_data(20, 0, [0,0,0,0,0,0,0,0])
time.sleep(0.0001)
4 changes: 3 additions & 1 deletion src/PololuRPiSlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*
* The second template parameter, pi_delay_us, specifies the delay.
* We recommend a value of 10 for an I2C speed of 100 kHz or a value
* of 0 for 400 kHz.
* of 0 for 400 kHz. However, on the Pi 3, CPU scaling will cause I2C
* to run at half the speed; in this case we recommend values of 20 or
* 5.
*
* Additionally, it implements a system of buffers allowing user code
* and the I2C system to read and write asynchronously from the same
Expand Down

0 comments on commit ebacaba

Please sign in to comment.