Python Tkinter- GPIO Pin function not working Python Tkinter- GPIO Pin function not working tkinter tkinter

Python Tkinter- GPIO Pin function not working


The first error:

RuntimeErorr: No access to /dev/mem. Try running as root!"

Means exactly what it says: you need to run your code as root in order to have appropriate access to the GPIO subsystem. When running as root, you get a different error:

NameError: global name 'averageReading' is not defined

This is happening due to errors in your code. First, you appear to have both a global variable and a function with the same name. Remove this line:

global averageReading

And also:

global measure

The global statement is for creating global variables, and only makes sense when used inside a function block.

There are a number of formatting problems in the code you've posted (there is missing indentation at on several lines), and it's hard to tell if this is just a copy/paste problem or if your code is actually incorrect.

Please try to fix any formatting issues in your question so that it matches your actual code.

Also, ECHO and TRIG are used in the measure function but aren't visible from there, so you'll need to fix this.