ME 405: Mechatronics Portfolio
Button_main.py File Reference

Created on Thu Jan 28 10:02:14 2021. More...

Functions

def Button_main.buttonPress (intrpt_pin)
  Button press function for external interrupt
More...
 

Variables

 Button_main.extint = ExtInt(Pin.cpu.C13,ExtInt.IRQ_RISING,Pin.PULL_UP,buttonPress)
 Set up external interrupt on button C13 of STM32-NUCLEO-L476RG.
 
bool Button_main.buttonFlag = False
 Define flag for button presses.
 
 Button_main.adcPin = ADC(Pin.cpu.A0)
 Declare analog input pin as an analog to digital conversion pin.
 
 Button_main.timer = Timer(2,freq = 200000)
 Create timer object to be used in ADC batch data collection. More...
 
 Button_main.time = uarray.array('i', (5*t for t in range(1000)))
 Define an array to represent span of time for data collection in microseconds.
 
 Button_main.adc = uarray.array('i', (0 for index in range(1000)))
 Define an array to store measured ADC counts.
 
 Button_main.myuart = UART(2)
 Define a UART object for serial communication.
 

Detailed Description

Created on Thu Jan 28 10:02:14 2021.

Author
Miles Young
Date
02/3/2021

Main program for button voltage data collection
This program, written in MicroPython, runs on the NUCLEO MCU and works in conjunction with the PC front-end program to collect data on the voltage of a built-in button after it is released from being pressed. The button, pin C13, must be connected to analog in pin A0 using a jumper wire or similar means. After receiving the signal from the front-end, ADC data is continously recorded in batches in an array. An external interrupt on the button is used to trigger the most recent batch being sent to the front end, as long as the batch is deemed valid. The program then resets, and awaits a new signal to enable data collection.

Function Documentation

◆ buttonPress()

def Button_main.buttonPress (   intrpt_pin)

Button press function for external interrupt

This function is called by the external interrupt on the built-in button C13. It changes a global variable buttonFlag to true if it is currently false, or else keeps it true if it is currently true. This is intended to allow the button to be pressed multiple times, with manual resets of buttonFlag required in the body of the program.

Variable Documentation

◆ timer

Button_main.timer = Timer(2,freq = 200000)

Create timer object to be used in ADC batch data collection.

A frequency of 200 kHz means ADC counts are read every 5 microseconds.