NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Need a JumpStart
July 22, 2010 by ioScream |
My kit it working wonderfully. I've managed to get the temp-sensor working and modified it with a few if-then statements to light LEDs based on temp as an exercise to get familiar with C and the microprocessor. Now I'm trying to delve a little deeper and get the LCD screen to report my CPU core temps (4), gpu temp, and gpu fan speed. As far as getting that information from my PC I have that covered. However, I'm trying get take that information and have it displayed on my LCD. I'm having trouble figuring out where to start. I'm able to read from the serial port using PuTTY, and display the input. However, this is all using the printf and scanf tutorial. I would like to automate this process using input from a file (6 in this case) and outputting to the LCD. I plan on using Python for all of this. So I imagine that the serial-comm.py would be a starting point. I managed to get the appropriate serial library installed, and the script running, but where do I go from here? I imagine I need to write a second script to open the 6 files, grab the last line, and send that to the serial-comm.py. Though, serial-comm.py appears to need changes. As well as the printf_and_scanf code. If I could just be pointed toward the right documentation, or google query I'll write the code. Really, any help would be appreciated. |
---|---|
July 22, 2010 by ioScream |
Okay, well I'm able to accept keyboard input from the serial port quiet easily. Now I need to work on the python side of things. Opening the files, reading the files, then sending them sequentially to the LCD to be displayed. It appears to be updating as soon as new input is entered, so it should be down-hill from here. Help is still welcome. Somewhat unrelated, but when I type something to be sent the LCD it sends as soon as I press space resulting in one word at a time being sent. Is this PuTTY doing this or the MCU aka bad coding? |
July 22, 2010 by hevans (NerdKits Staff) |
Hi ioScream, It looks like you are well on your way with your project. Putty should be sending the characters down the serial port as soon as they are typed. If they are showing up when you type space there is probably something in your MCU that is making that happen. Implementing the functionality you are looking for in python should not be too difficult, you are right that PySerial is the place to start. We have at least one example of sending data to the MCU using PySerial in the source code for the Multi-Panel LED Array (check out serial-comm.py). Hope that helps. Humberto |
July 22, 2010 by ioScream |
Well this code I am using is this: scanf_P(PSTR("%s"), &x); Which, in my best estimation, wait's for input before displaying (apparently the space character is a go). Is there a better way of getting the information from the serial port? Keep in mind I will have 6 separate sets of numbers that will need to be placed into variables coming down the line. I would like be able to format them. Core 1: xx Core 2: yy etc.. |
July 23, 2010 by ioScream |
Where I am: MCU is accepting data from Python, formatting it as needed outputting to LCD.. Python is sending data (simulated temps/speeds with random.randrange) What I need: Getting the temperatures is requiring me to learn a touch of VS C++ to write a file as I am using the monitoring program's SDK (found the lines I need just need to output to a file). Python needs to read that file into some strings and output with existing code. Hopefully I won't run into file handling issues with Python reading, and VS C++ writing.. This is sort of a log for me, though I am always open to help/advice. |
July 23, 2010 by ioScream |
Quick question. Can Python "hook" into shared memory? Instead of me dealing with the C++ that I referred to, can I use Python to find those values in the memory? If so, where do I need to look first in order to get an idea of how to do this with Python? |
July 23, 2010 by hevans (NerdKits Staff) |
Hi ioScream, I am having trouble seeing exactly what it is you are trying to do. Is there data being generated by some C++ program that you want to display on your MCU? Where is this data coming from? For the most part, in any well behaved operating system you will not be able to access the memory of one program from inside another program. If you do need to have two different programs talk to each other you might want to look into using sockets. They are very easy to work with in Python, and most programming languages have good support for sockets. It is basically a pipe you can send data back and forth over. Your other option is to send data directly over the serial port to the MCU via your C++ program. It is a bit more cumbersome than Python, but it there are a few examples out there. Humberto |
July 23, 2010 by ioScream |
Thanks for the advice. I moved this thread to the Projects section. I had it here because I originally thought that it was going to be harder to program the MCU than it was.. and I'm currently beyond the scope of "MCU Programming".. but to answer your question here is where I am at: The program is a windows exe, however, it comes with an SDK with example code in visual cpp that shows how to access it's shared memory named "RTHMSharedMemory". I've managed to use mmap in Python to access that shared memory, however, the memory is "encoded" with DWORD. Right now I'm trying to figure out the appropriate ctypes code in Python to "decode" that DWORD data into readable data because Python doesn't appear to have any libraries dealing directly with DWORD. I'm really happy with Python thus far, and am I glad that when I am finished I will only be loading 1 additional process. This is really the last step as I already have a working model that is just requiring the correct data, and now that I have access to the data I'm anxious to get it in a readable format. Do you think the MCU could handle DWORD? If so, how would you recommend dealing with it? I have the DWORD data here, but it will not display correctly if I simply copy & paste. |
Please log in to post a reply.
Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...
|