So I started a project on a microcontroler that uses I2C communication a month ago with no knowledge about anything but python.
I have to talk to a peristaltic pump that uses ASCII strings for communication. So my setup currently consists of a Raspberry Pi, the I2C bus, Arduino and the peristaltic pump. The Arduino is only used as a powersupply. I thought a good starting point would be just to try and turn the pumps LED on and off. The code for LED on is "L,1" and for LED off is "L,0". (The "" indicates that whats inside it is the absolute code). [a link] https://www.atlas-scientific.com/_files/_datasheets/_peristaltic/EZO_PMP_Datasheet.pdf
By using smbus.SMBus in python I sent the data through the command through write_i2c_block_data. Documentation of smbus gives the following: write_i2c_block_data(int addr,char cmd,long vals[]) however i dont understand what is meant with 'char cmd'. I couldnt put a string command in there and it only worked when I put an integer in there.
Here is the code:
import smbus
import time
bus = smbus.SMBus(1)
slave_address = 0x67
led_on = 'L,1'
led_off = 'L,0'
def string_to_charlist(a_string):
stringlist = list(a_string)
return stringlist
def string_to_intlist(a_string):
lst = string_to_charlist(a_string)
intlist = []
for i in range(len(lst)):
an_int = string_to_charlist(lst[i])
intlist.append(an_int)
return intlist
ledon_intlist = string_to_intlist(led_on)
ledoff_intlist = string_to_intlist(led_off)
# this will result in ledon_intlist = [76,44,49]
# this will result in ledon_int =list [76,44,48]
command1_on = ledon_intlist.pop(0)
command1_off = ledoff_intlist.pop(0)
for i in range(1):
time.sleep(0.5)
bus.write_i2c_block_data(slave_address, command1_on, ledon_intlist)
time.sleep(0.5)
bus.write_i2c_block_data(slave_address, command1_on, ledon_intlist)
After running this code through the raspberry Pi command prompt the pumps LED started blinking on the given time frame. Unfortunately it never stopped blinking and also didt show up when I searched for it using i2ctools command i2cdetect -y 1
I assume the pump's chip is in an infinite loop now.
My questions are: 1. How should one use the write_i2c_block_data() command and what argument does it take. Currently I figured that the 1st argument is the slave address, 2nd is the initial byte of the stream and the 3rd argument is the rest of the stream integer values to be sent. 2. What possibly could have gone wrong that the pump is stuck in an infinite loop and how do I fix it