<< return to Pixycam.com

User Tools

Site Tools


wiki:v2:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
wiki:v2:python [2021/12/24 12:30]
kees Added description for flags in get_line_tracking_data()
wiki:v2:python [2021/12/30 13:02]
kees Added set_next_turn() and set_default_turn() and removed some typos
Line 15: Line 15:
 In this tutorial we will describe the following platforms: In this tutorial we will describe the following platforms:
  
-  * Raspberry Pi: using USB and the libpixyusb2 library. 
   * LEGO Mindstorms EV3 using Python on the ev3dev operating system.   * LEGO Mindstorms EV3 using Python on the ev3dev operating system.
   * LEGO Mindstorms EV3 using MicroPython with PyBricks.   * LEGO Mindstorms EV3 using MicroPython with PyBricks.
 +  * Raspberry Pi: using USB and the libpixyusb2 library.
  
 This tutorial belongs to Pixy2 and Pixy2.1. If you own the previous Pixy, go This tutorial belongs to Pixy2 and Pixy2.1. If you own the previous Pixy, go
 to the chapter "Pixy for LEGO Mindstorms"​ in the tutorial to the chapter "Pixy for LEGO Mindstorms"​ in the tutorial
-[[https://​github.com/​KWSmit/​Pixy_ev3dev|over here]]. That tutorial is written +[[https://​github.com/​KWSmit/​Pixy_ev3dev|over here]]written 
-by one of our customers. +by one of our customers ​which explains how to use Pixy on LEGO Mindstorms EV3.
- +
-===== Rasberry Pi ===== +
- +
-<Work in progress>​+
  
 ===== LEGO Mindstorms EV3 ===== ===== LEGO Mindstorms EV3 =====
Line 177: Line 173:
 from pixycamev3.pixy2 import Pixy2 from pixycamev3.pixy2 import Pixy2
  
-prixy2 ​= Pixy2(port=1,​ i2c_address=0x54)+pixy2 = Pixy2(port=1,​ i2c_address=0x54)
  
 # Get version # Get version
Line 198: Line 194:
 from pixycamev3.pixy2 import Pixy2 from pixycamev3.pixy2 import Pixy2
  
-prixy2 ​= Pixy2(port=1,​ i2c_address=0x54)+pixy2 = Pixy2(port=1,​ i2c_address=0x54)
  
 # Get frame resolution # Get frame resolution
Line 219: Line 215:
 from pixycamev3.pixy2 import Pixy2 from pixycamev3.pixy2 import Pixy2
  
-prixy2 ​= Pixy2(port=1,​ i2c_address=0x54)+pixy2 = Pixy2(port=1,​ i2c_address=0x54)
  
 # Turn upper leds on for 2 seconds, then turn off # Turn upper leds on for 2 seconds, then turn off
Line 331: Line 327:
 | <​code>​ | <​code>​
 from pixycamev3.pixy2 import Pixy2 from pixycamev3.pixy2 import Pixy2
 +
 +pixy2 = Pixy2(port=1,​ i2c_address=0x54)
  
 # Detect barcodes and print their number # Detect barcodes and print their number
Line 338: Line 336:
         for i in range(0, data.number_of_barcodes)         for i in range(0, data.number_of_barcodes)
             print('​Barcode number: ', data.barcodes[i].code)             print('​Barcode number: ', data.barcodes[i].code)
 +</​code> ​                                                                     ^^
 +
 +^ %%set_next_turn(angle)%% ​                                                  ^^
 +| **Description:​** ​                                                          ^^
 +| Set direction for turn at the next intersection. After this intersection ​  ^^
 +| Pixy2 will choose it's default turn again. ​                                ^^
 +| **Parameters:​** ​                                                           ^^
 +| angle | Direction to choose at the next intersection (-180, 180  degrees) ​  |
 +| **Returns:​** ​                                                              ^^
 +| None                                                                       ^^
 +| **Example:​** ​                                                              ^^
 +| <​code>​
 +from time import sleep
 +from pixycamev3.pixy2 import Pixy2
 +
 +pixy2 = Pixy2(port=1,​ i2c_address=0x54)
 +
 +# Set next turn to 90 degrees
 +pixy2.set_next_turn(90)
 +</​code> ​                                                                     ^^
 +
 +^ %%set_default_turn(angle)%% ​                                               ^^
 +| **Description:​** ​                                                          ^^
 +| Set default direction for all intersections. ​                              ^^
 +| **Parameters:​** ​                                                           ^^
 +| angle | Default direction (-180, 180 degrees) ​                              |
 +| **Returns:​** ​                                                              ^^
 +| None                                                                       ^^
 +| **Example:​** ​                                                              ^^
 +| <​code>​
 +from time import sleep
 +from pixycamev3.pixy2 import Pixy2
 +
 +pixy2 = Pixy2(port=1,​ i2c_address=0x54)
 +
 +# Set default turn to 0 degrees (straight on)
 +pixy2.set_default_turn(0)
 </​code> ​                                                                     ^^ </​code> ​                                                                     ^^
  
Line 344: Line 379:
 You'll find more practical sample code in the You'll find more practical sample code in the
 [[https://​github.com/​charmedlabs/​pixycamev3|Github repository]]. [[https://​github.com/​charmedlabs/​pixycamev3|Github repository]].
 +
 +===== Rasberry Pi =====
 +
 +<Work in progress>​
  
wiki/v2/python.txt · Last modified: 2021/12/30 14:48 by kees