This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
wiki:v2:python [2021/12/05 13:58] kees 211205 - Several edits in text |
wiki:v2:python [2021/12/08 15:24] kees 211208 - Update installation process and import path |
||
---|---|---|---|
Line 82: | Line 82: | ||
==== Installing Python API ==== | ==== Installing Python API ==== | ||
- | This Python API works both with Python3 and MicroPython. | + | This Python API works both with Python3 and MicroPython. There are two ways |
+ | you can walk to use the API: | ||
- | <TODO: explain how to add python file with API to the project or how to | + | === 1. Installing with ''pip'' === |
- | install the API with ''pip''. In case of installing with ''pip'' explain how | + | |
- | to install for Python3 and MicroPython> | + | > At the moment this method only works for Python3. |
+ | |||
+ | First login to your EV3 using ''ssh''. Run the following command | ||
+ | in a terminal window on your computer: | ||
+ | |||
+ | <code> | ||
+ | $ ssh [email protected] | ||
+ | </code> | ||
+ | |||
+ | where ''robot'' is the default username in ev3dev and ''xxx.xxx.xxx.xxx'' | ||
+ | is the IP-address of your EV3. You will be asked for a password. The default | ||
+ | password is ''maker''. Be sure to use you're own combination of username and | ||
+ | password if you changed the default in ev3dev. | ||
+ | |||
+ | When logged in to EV3, you can install the API package on your EV3 with: | ||
+ | |||
+ | <code> | ||
+ | $ python3 -m pip install pixycamev3 | ||
+ | </code> | ||
+ | |||
+ | This takes about four minutes on the EV3. ''pip'' is not installed | ||
+ | out-of-the-box on ev3dev. You can install ''pip'' with: | ||
+ | |||
+ | <code> | ||
+ | $ sudo apt install python3-pip | ||
+ | </code> | ||
+ | |||
+ | Beware this takes about 18 minutes on the EV3! But you can use | ||
+ | ''pip'' later on to install other python packages when needed. | ||
+ | |||
+ | When package ''pixycamev3'' is installed you're ready to program! Go | ||
+ | to the next paragraph [[#Using Python API|Using Python API]]. | ||
+ | |||
+ | === 2. Adding the API to your project folder === | ||
+ | |||
+ | This method works for both Python3 and MicroPython. | ||
+ | |||
+ | In your project folder create a new folder ''pixycamev3''. Visit the repository | ||
+ | on [[https://github.com/charmedlabs/pixycamev3/tree/main/pixycamev3|Github]]. | ||
+ | Add the file pixy2.py to your folder ''pixycamev3''. The easiest way is to open | ||
+ | this file in Github and click on the ''Raw'' button right above the code window. | ||
+ | Then select all text of the file and copy it to a new file named ''pixy2.py'' | ||
+ | in your ''pixycamev3'' folder. | ||
+ | |||
+ | Your project folder structure should look now like this: | ||
+ | |||
+ | <code> | ||
+ | project | ||
+ | ├── pixycamev3 | ||
+ | │ └── pixy2.py | ||
+ | └── main.py | ||
+ | </code> | ||
+ | |||
+ | The file ''pixy2.py'' works for both Python and MicroPython. When you copied | ||
+ | the file you're ready to program! | ||
==== Using Python API ==== | ==== Using Python API ==== | ||
Line 103: | Line 158: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
pixy2 = Pixy2(port=1, i2c_address=0x54) | pixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 122: | Line 177: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
prixy2 = Pixy2(port=1, i2c_address=0x54) | prixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 143: | Line 198: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
prixy2 = Pixy2(port=1, i2c_address=0x54) | prixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 164: | Line 219: | ||
| <code> | | <code> | ||
from time import sleep | from time import sleep | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
prixy2 = Pixy2(port=1, i2c_address=0x54) | prixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 187: | Line 242: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2, Pixy2Mode | + | from pixycamev3.pixy2 import Pixy2, Pixy2Mode |
pixy2 = Pixy2(port=1, i2c_address=0x54) | pixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 217: | Line 272: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
pixy2 = Pixy2(port=1, i2c_address=0x54) | pixy2 = Pixy2(port=1, i2c_address=0x54) | ||
Line 277: | Line 332: | ||
| **Example:** ^^ | | **Example:** ^^ | ||
| <code> | | <code> | ||
- | from pixy2 import Pixy2 | + | from pixycamev3.pixy2 import Pixy2 |
# Detect barcodes and print their number | # Detect barcodes and print their number |