Introduction: PC RAM-usage to Arduino Via Serial-port
A friend of mine got me inspired with his small Arduino project. This little project involves the Arduino UNO R3, which is reading data by a program made in Arduino IDE sent to a serial port (USB-port) by a C# program made in visual studio. As this was my first ever build including an arduino, I'm pretty happy with the outcome, and I've learnt a bit or two about how to connect wires and how to program the arduino. Since I'm no expert in any way of programming or handling micro-controllers you can expect pretty basic instructions, but I will try my best to explain the project for you. Hope you'll enjoy this instructable. This project can be developed much more, in the future I think I will make a dashboard where you can monitor RAM-usage, CPU-usage and GPU-temp and...Well you get the idea, "there are so many possibilities these days" :)
Step 1: The Stuff You Will Need
1x Arduino UNO R3
1x USB A Male to Type B Plug cable.
12x 220 OHM resistors
12x wires (I'm using speaker-wires, works perfectly) and 12x male-to-female jumper wires OR 12x male-to-male jumper wires (the choice is yours)
12x straight needles(those metal pins that use to come in the same package that the Arduino itself)(see image)
1x 7 Segment 4 Common Cathode 0.36" RED LED Digital Display
1x soldering iron with solder
1x wire stripper
1x copper pipe (at least 11 mm inside Ø(diameter) if using 2 copper pipes like me)
Heat Shrink Wire Wrap (2.5 mm Ø(diameter))
1x thin wooden-board (You can make what design you want, mine looks a bit clumsy, I think :) Make something you would like to look at. A 3D printer would come in handy here)
Step 2: Wiring
A breadboard would come in handy here too, if you like to test the wiring before you start soldering together the resistors and wires.
BUT if you know your stuff, like me *ehm*, you can start soldering together everything at once. !!!BUT NOT TO THE ARDUINO!!!
This is pretty straight forward, the pictures says it all, I think :)
Here the soldering iron will come in handy, since we need to solder the wires to the display's pins and the resistors to the 4 COM-pins on the display (COM1, COM2, COM3, COM4) as shown in the first image. (The resistors don't need to be facing the same directions, but I like consistency so...)
If you use shrinking plastic for the wires, which I do recommend (to minimize the risk of short-circuit and statics/disruptions). You can like me use the soldering iron's not so hot part (higher up on the soldering iron) or a lighter to shrink the plastic, you decide.
I do recommend tagging the wires so you know which wire will go where, it'll be so much easier when starting to assemble the whole project (at least for me and my weird design...).
I also recommend to solder the "black-tiny-plastic-metal-pins" things to the end of the wires (see two last images)
When you have soldered the wires onto you display's pins you can start connecting the wires to your Arduino UNO (see first image).
Step 3: Arduino IDE Installation and Finding the Right Port
First you need to install the Arduino IDE ( use this link: https://www.arduino.cc/en/Main/Software ) depending on what OS you have(I use Windows 10) you need to download it for the right one, so for Windows 8.1^, you can go to the Microsoft store and download the Arduino IDE software there (or follow the link above).
now you need to connect the Arduino UNO to one of your pc's USB-port and figure out which COM-port you're connected to with your Arduino, but how? Well you can go to device management on windows by right-clicking the windows logo on the taskbar and click on DEVICE MANAGER (see images), there should be one named USB-serial, that's the right port.
And then in the Arduino IDE program click tools and then port and set it to the right port (for me it's COM4).
Step 4: The Code for Arduino UNO
Now we can begin with the interesting part, CODING!
First you will need to assign the twelve(12) pins of the display to different variables(see 1st image).
(The COM-pins are for which "position" will light up)
Then you need to make some more variables and an array which will take the characters the port receives and place it in its array(see 2nd image).
Now you need to setup the pins or ports on your Arduino to OUTPUT(see 3rd image)
I will come back to the loop in a bit, but first you need to make the numbers to show properly on the display.
Now we are going to make functions for the numbers 1-9 on the display(see 4th, 5th and the 6th image)
Since I'm not going to display anything on the first position on the display, I made three(3) functions for the rest of the positions (each for one position). You need to make a function for every digit-position for which will show a specific number(see 7th, 8th and the 9th image).
I also made a reset function for making the data shown on the display more reliable(see 10th image).
Now for the loop, which is going to loop when the program is running.
You can now compile and upload the code to the Arduino by clicking the upload button (the program will compile and upload to the Arduino if the compile is successful).(see 11th image)
Step 5: Code for Sending RAM-usage to Serial Port (C#)
Now I'm going to show you one way to send data to a serial port in C#.
I'm using visual studio 2017 when coding. The code is not long at all, but it took a while to figure out some parts, i.e how to get the program to run when computer starts and not showing an ugly console window at the desktop or the taskbar, well, enough ranting, let's get right into the code!
So to start of with this code-project in visual studio, you can start of by clicking on file and new project (see 1st image) and then select VISUAL C# and then WINDOWS CLASSIC DESKTOP and finally click CONSOLE APP (.NET FRAMEWORK) and of course name it whatever you want and save it wherever you like. (see 2nd image)
Now you can start coding the program...
you will need those using directives (see 3rd image), well actually you don't need all of them, but it doesn't matter if they're there.
And the main code looks like this (see 4th image) remember to use the same PORT and BAUD-SPEED (9600) as the one on the ARDUINO UNO Code!!! (see 5th image). And also remember to check how much RAM YOU have, I have 8 GB(7.90 GB) of RAM installed so, that's the reason I have 7.90 in the code (see 4th image).
If you wonder why I have DllImports, it's because I wanted to hide the window entirely from the user, in this case, ME, because the program will start automagically when the computer boots up. But I will explain more about that later.
At this point it is best if you test both the Arduino- and the C#-program and make sure there are no errors. It's very important that you have the Arduino program running before you start running the C# program, because otherwise it doesn't work.
Now when the program is written, you can navigate to the programs folder until you find the bin-folder and the open it, and then double-click the debug folder and there it is, *phew* your golden application/program, now right-click it and then click create shortcut... Then on your keyboard press down the (windows)⊞ -key + R-key. Then write in the textbox: shell:startup and press (enter/return)↵-key now when you're in that folder I want you to drag your created shortcut of your application to the startup folder. And there you go... Now the program is going to start when you boot up your computer.
Now everything should work, if not, well you better start searching for the problem :) .
Step 6: Building the Case
Now we can get to the more physical part of actually building the construction, keep in mind that you will have to make some adjustments for the case to fit everything in. It's a very tight fit in my case for everything, so I do recommend making it a little bigger everywhere. But if you want to make one just like mine, then I'll give you some basic measures and how to piece it together. To cut the pipes I used a pipe cutter, they're perfect for eh, cutting pipes, meh, no shit...
Obviously it is good to test so that nothing is loose throughout the whole building process by plugging it to your computer and start the C# program (remember to put the Arduino in the same USB-port as before).
So first off you need a wooden board that are approximately 4 mm (0.157 in) thick. See 1st image for details on measurements of all the pieces.
I'm a using hot glue gun since it's easy and fast, I do recommend that, but it's up to you what you will use...
PS. I think the images will describe the process a bit better, but be sure to read through this: I'm using a snap blade utility knife for cutting the pieces out, it took a while, but when that's done you can cut out where the display is going to be (on the 60 x 45 mm piece), you have to fit the display very tightly in the "display-hole" when you have done that you can drill holes in the bottom part of the "display-box" to fit the copper pipes in, it is also important that the pipes fit tightly in the holes. Now you can start driving the wires from the display through the pipes (if you're using two(2) pipes you can split number of cables so they will fit through the pipes(six(6) wires in each pipe...)(see 2nd, 3rd, 4th, 5th, 6th and 7th image)).
PS. I don't thinks its necessary, but if you want you can drill some holes in the bottom so the Arduino can "breathe" a little. (see 10th image).
Now you will have to drill holes for the pipes on "The base"-top board (see 8th image). When you have glued all the pieces together, BUT remember to leave one side unglued all the time, so you can get the Arduino out in case of usage elsewhere. I used two(2) small magnets and two(2) small metal pieces to make sure the side-wall is in place. you can start plugging the wires (IF you have done like me, namely used regular speaker wires, you can connect the wires to female-to-male jumper wires and then to the Arduino) be sure to plug in the right ports on the Arduino. (see last image)
As the edges were pretty ugly on the whole thing I decided to use thin rope to cover up the edges, I think it looks pretty nice in the end. But remember that the design wasn't the main idea of the project for me this time, so be sure to make yours even prettier than mine *that's not too difficult*.
Step 7: IT'S ALIVE AND WORKING!
MAKE SURE TO ASK ME ANYTHING IF YOU ARE UNCERTAIN ABOUT SOMETHING REGARDING THIS PROJECT, AND I WILL TRY MY BEST TO EXPLAIN IT FOR YOU!
(I WILL ALSO TAKE SUGGESTIONS ON HOW TO MAKE THE CODE EVEN BETTER SINCE I'M NO EXPERT ON ARDUINO UNOS).