PYTHON GUI with microcontroller

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,

 

Am working on a project that makes use of an avr microcontroller and a raspberrry pi. The pi is used to create a GUI to display data from the microcontroller (microcontroller connected via usb to the pi). But any time i try to open the interface inside via the raspberry pi terminal, i get the error <line 97 in serial_comms.py <serial thread> object has no attribute main window>. I don't know what might be the issue. Will also love to know how the python gui is able to communicate with the firmware of the microcontroller module (if there is a way the gui program can identify the firmware or something). Please am still a novice and its a work project, i'll gladly appreciate your response.

Josh

Last Edited: Fri. Nov 8, 2019 - 02:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the USB interface on the AVR board? 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This forum is for finished projects, I'll move the thread to general programming.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Will also love to know how the python gui is able to communicate with the firmware of the microcontroller module 

What do you mean?  YOU are creating the communication messages in your AVR code, probably through a simple serial setup.   

 

So, for example, your pressure sensor at the AVR board causes a serial string to be sent: "PSENSE1=23.18psi"  or "VBATT=11.63Volts" or "DOORSW5=OPEN" to the GUI, then the GUI will take that information & perhaps display it as a meter gauge, digital readout, or maybe it will look at the numbers & display a big red flashing alarm "EXTREME PRESSURE DETECTED--EVACUATE NOW!", or "SECURITY BREACH AT DOOR 5--TEAR GAS ACTIVATED"...this is up to YOU--as the creator & master of ceremonies.

 

So far you have given no details of your softwares...so it's hard to say much more until then.

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

raven231996 wrote:
<line 97 in serial_comms.py <serial thread> object has no attribute main window>

That in itself rings alarm bells. Why is a lower level module like serial comms accessing the Main Window. but that's only an architectural problem.

 

You'll have to read the documentation from whoever wrote that program; you're probably not using it ccorectly.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you think this has anything to do with the AVR ?

 

raven231996 wrote:
microcontroller connected via usb to the pi

More detail, please!

 

raven231996 wrote:
serial_comms.py

Suggests that it is a plain USB-to-serial adaptor - yes ?

 

In which case, you should start by removing the AVR from the equation - just use a serial terminal on a PC, or another Pi, or whatever, to send whatever serial stuff you expect your AVR to be sending.

 

Get your RPi stuff debugged & working before you try adding the complications of the AVR!

 

raven231996 wrote:
i get the error <line 97 in serial_comms.py <serial thread> object has no attribute main window>

that really sounds like a purely Python error within your RPi code - nothing to do with the AVR.

 

You would be far better on an RPi and/or Python forum for help on that!

 

raven231996 wrote:
Will also love to know how the python gui is able to communicate with the firmware of the microcontroller module

Surely, you must know that to be able to even start this project?!

 

raven231996 wrote:
still a novice and its a work project

Then you really need to go to your boss / supervisor / co-workers for help with this.

 

They must know that you're a novice and, therefore, must be expecting to provide assistance.

 

We know nothing about you or your experience - they do

 

They know what you've got & what you're supposed to be doing - we don't

 

They can see exactly what you've done - we can't

 

They can see exactly what is happening - we can't

 

etc, etc, ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Note that Rpi have extensive fora:

 

https://www.raspberrypi.org/forums/

 

and one specifically for Python on Rpi:

 

https://www.raspberrypi.org/forums/viewforum.php?f=32&sid=39f61573f6a8a414711f5b3c9b7a029a

 

I'd suggest your question is much better targeted there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am thinking that the OP might  be trying to use a USB programming interface for serial comms. So, serial_comms.py has no COM port to attach to. If so, that is  not an RPi problem.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

My go-to for USB communication is PySerial and a virtual serial port,

partly because I do not know how to write any other host code.

Trying to read about PyUSB makes my eyes water.

Another reason is that it's always been fast enough.

I've managed 1 Mbps with a 1287.

I've never really been motivated to figure out HID.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
OP might  be trying to use a USB programming interface for serial comms.

And, of course, the person(s) best placed to spot & help with that sort of error would be the OP's boss / supervisor / co-workers.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My googling suggests that PySerial is not normally called serial_comms.py but simply serial.py but that sometimes on the RPi "import serial" can be confused with the user's own code so I've seen a suggestion on Stackoverflow to rename it to serial_comms.py. As such it's very difficult to know which file from PySerial the file serial_comms.py mentioned in #1 actually is and therefore what is actually contained on line 97.

 

Also, OP has not posted his Raspberry code that is invoking PySerial anyway. I rather suspect it's simply a usage error.

 

On the internet there are many examples of using the Python Serial library such as:

 

https://pyserial.readthedocs.io/en/latest/shortintro.html

 

where it looks like it really should be as simple as opening a dev/ttyUSB (which seems to be what Raspberry enumerates Vcoms as) and then using the .write() method on the object.

 

But I believe this needs a Raspberry Python user to take a look at all that is being done and what the error really means.

 

It's true that the mention of "main window" seems odd - Pyserial is a service - nothing to do with a Window object that might be involved in GUI implementation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
it really should be as simple as opening a dev/ttyUSB

Assuming that the OP's connection to the microcontroller is actually a virtual serial port.

Jim has cast doubt on that ...

 

clawson wrote:
the mention of "main window" seems odd

I would guess, from the Subject/Title, that the OP's task is to build a GUI, and use PySerial "underneath" it for the comms.

 

In such an application, I don't think it would be unusual to have separate threads for the GUI and the comms ...

 

Again, the OP really should be seeking local support for all this.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0



And, of course, the person(s) best placed to spot & help with that sort of error would be the OP's boss / supervisor

Sounds like it's time for some good Dilbert cartoons!

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

version problem?