[go: up one dir, main page]

0% found this document useful (0 votes)
11 views3 pages

06 - Pymata4 Guide

The document provides a QuickStart guide for using Pymata4 with Arduino, detailing the initialization process, pin setup, and the differences between digital and analogue pins. It explains how to use pins for input and output, including PWM functionality, and emphasizes the importance of resetting and shutting down the Arduino board after program completion. Proper pin management is crucial to avoid runtime errors and ensure the Arduino is recognized in future sessions.

Uploaded by

ahnxfislxm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

06 - Pymata4 Guide

The document provides a QuickStart guide for using Pymata4 with Arduino, detailing the initialization process, pin setup, and the differences between digital and analogue pins. It explains how to use pins for input and output, including PWM functionality, and emphasizes the importance of resetting and shutting down the Arduino board after program completion. Proper pin management is crucial to avoid runtime errors and ensure the Arduino is recognized in future sessions.

Uploaded by

ahnxfislxm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

QuickStart guide to using Pymata4 (once it’s installed)

Initialising

Every program file which uses pymata4 requires the import line at the top of the file, to get the
pymata4 module from the installed pymata4

<- pymata4 import line

To connect with an Arduino board the program needs to look for and set up the board for use, saving
it as a variable with any name (in this example, board).

Is <- the variable called board saves the Arduino to be used


which is found using the Pymata4 function of pymata4

Before the Arduino pins will do anything, they need to be set up for appropriate use. This can be
analogue or digital, input or output, or a couple of special settings. The function to set the pin type is
used in reference to the Arduino board which was previously set up.

Each pin on the Arduino corresponds to the number next to it when setting up the pins. Pins 0 to 13
are digital and the pins A0 to A5 are analogue. The analogue pins can be set as digital pins and are
referenced as digital pins 14 to 19. DO NOT USE DIGITAL PINS 0 or 1 as these are used by pymata4
to communicate with the Arduino.

To use a pin as analogue or digital it must be set as analogue mode or digital mode respectively

<- digital pin 4 set as digital input mode (this will


return either in a high or low value as a 1 or 0 respectively)

<- analogue pin A0 set as digital output


mode (can send out 1 or 0)

<- analogue pin A0 set as analogue input


mode (this will return a representation of the value as an integer in the range of 0 to 1023)

A digital pin is an Arduino pin that can send or receive data as a 1 or a 0, a high or a low. These pins
will be at one of these values and cannot be anything in between, eg. a digital pin CANNOT have a
value of 2. These pins are used when all that you care about is if it is on or off, the specific on or off
value is not important.

An analogue pin is an Arduino pin which can receive and classify data across a range of values. This
range is between 0 to 1023. These pins are used when the voltage on the pin is variable AND you
wish to make a decision or perform actions based on this difference.
<- differences between analogue and digital, analogue has a
range while digital is either at high (5V in this case) or low (0V in this case)

Specific digital pins (3, 5, 6, 9, 10 and 11) can also be set as Pulse Width Modulation (PWM) output
signals. On the Arduino board the pins which can do PWM have a ~ next to the number. A PWM
signal has a period of time it is high/1 and a period of time it is low/0. The period of time it is on is
called the duty cycle.

<- A range of signal outputs for different


PWM signals. during TON the pin has a high/1 value and during TOFF the pin has a low/0 value

To use PWM the pin must be set as PWM mode.

<- digital pin 3 set as PWM output mode (this will


output a signal which is high for a time and low for a time)

Note that there is no analogue output.


Using Pins in the program

When using the pins in your code, what you can do and the functions you can use depend on the pin
type which you have chosen. All the functions are used in reference to the Arduino board previously
set up.

Inputs will use a read function, where the wire connected to the pin is checked, and the information
‘on’ the wire is brought into the program. These functions only take in the pin which the Arduino
needs to look at:

<- looks at digital pin 4 and gives a 1 or a 0 depending on if pin 4


is high or low

<- looks at analogue pin 0 and gives a value between 0 and 1023
depending on the voltage at pin 0

Outputs will use a write function, where the pin will send out a signal (value) onto the wire
connected to the pin, which your circuit will then receive. They take in the pin which the Arduino
needs to send a signal to, and the value which you wish to set the pin to.

<- sets the value of analogue pin 0 as 1/high

PWM output will use a PWM write functions, where the pin will be sent a signal which is high for a
period of time and low for a period of time depending on the input to the function. They take in the
pin which Arduino needs to send a signal too, and a value between 0 and 255 which represents the
percentage of time it is “on/high”. If the signal is 0 it is always off, and if it is 255 it is always on.

<- sets the PWM digital pin 3 to be on for half for the time
period, as 128 is half 255.

Resetting the Board and ending the program

The Arduino board can be reset to the base functionality at any time using the reset function, which
will remove pin modes and any values which are written to the pins. This is to be used when whilst
the program is running you need to reset the Arduino board.

<- will cause the Arduino board to reset when the program runs it

When the program is complete is it good practice to appropriately shut down the Arduino board. This
will also reset the board as part of the process and should only be run when the program is
complete. This can be done using the shutdown function.

<- will shutdown the Arduino board and reset it for when the program is
completed

If you do not shutdown your board any previous value which you saved to the pins through the
program will still be set on the arduino. This may lead to output even when the program is no longer
running and can lead to the computer not recognizing the Arduino the next time you run the
program. See the Arduino Troubleshooting Guide for more information on Runtime errors

You might also like