![]() call millis function - how much ms passed since loop cycle startĪnd the whole thing basically works like magic. integer to store calculation result for speed array of two values for direction & speed unsigned long to call the arduino's "millis()" function maximum wait time for bytes is 1/10th second Since I'm sending an array through the serial, and not just one value, from what I gathered from various forum posts and research into the serial connection and timeout argument in PySerial, on the Arduino end - I'm gonna need to give it a little timeout - which is how long to wait until it gets all bytes - and a loop in which to process the incoming bytes. The second half, of course, is the Arduino code. So I'll be adding the commands to the code, at the end of the loop: ![]() The code will also need to convert the array to a byte array, from what I've gathered, before writing it to the serial. Speed = cv2.getTrackbarPos('Speed','Motor Control')ĭirection = cv2.getTrackbarPos('Direction','Motor Control')Īnd here's the little interface that opens up when the code is run: # get the current positions of the two trackbars # quit the loop if keyboard key Q is pressed ![]() # show the window with the logo and trackbars # create the two trackbars that will be usedĬv2.createTrackbar('Speed', 'Motor Control', 0, 10, nothing)Ĭv2.createTrackbar('Direction', 'Motor Control', 0, 1, nothing) # create a window to put the trackbars in will be used when actually running with serial connected # serial is commented out for the moment because not currently used. Logo = cv2.imread('./interacing_pictures/motor.jpg') # define an empty function, since the trackbar requires a function of some sort Here's just the Python code with commented documentation (it's not sending anything to serial yet): Oh and I also made a tiny logo to display in the interface :) I will also be using the OpenCV package, which I already have installed on my machine, to create the trackbar window. I'll declare the serial port without a timeout component, because I'm not reading anything in the Python code, I'm only writing into the microcontroller. Since my computer already has Anaconda installed on it, installing new packages on anaconda is fairly simple.įor this one I used the command (from the Anaconda scripts folder): This means that I'll be sending not just a single number through the serial port, but an array, which will look like this: įirst I'll quickly write the Python code, using the PySerial package. Simply put, the trackbar will tell the microcontroller to output an analog output between 0 to 254, depending on the trackbar's position between 0 to 10, and control the direction based on whether the second trackbar is 0 for left, or 1 for right. The first step about getting anything done is to know what it is you're doing - so I'll be doing a very simple interface:Ī trackbar moving between 0 and 10, which will control the rotation speed of a motor, and another trackbar between 0 and 1, which will control the direction. ![]() This week is about interfacing with the Arduino through the serial port PC connection. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |