Click here to Skip to main content
15,942,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm still new to the world of programming but I need some help with this if it's possible. If not, that's okay too.
I have this task where I have to establish a connection between C# (WPF) and Arduino. Now, I managed to connect the LCD so it outputs the values from the potenciometer to the LCD screen like in this Picture Once I have the connection between Arduino and C#, C# must output those values from the potenciometer to the "Line" form. So, in shorter words, How I change the current value with the potenciometer, the line in C# MUST be moving as I do it. I'm very bad at explaining so hopefully You understood what I was saying :P If anyone could help me with this task, I'd be more than happy. Thanks in advance

Programs: Microsoft Visual Studio (2008-2015), Arduino (latest version)
Language: C#
Application: WPF (.NET Framework 4.5)
OS: Windows

Line Form code:
      X1="1" X2="1" Y1="0" Y2="1"
            <RotateTransform CenterX="1" CenterY="{Binding ActualHeight, ElementName=TheLine}"

                              Angle="{Binding Path=Value, ElementName=AngleSlider}" />
<StackPanel Grid.Column="1">
    <Slider Name="AngleSlider" Minimum="-90" Maximum="90" Value="0" Height="59" Width="200" />

Arduino code:

#include <LiquidCrystal.h>

 // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor

 void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.

 void loop() {
  lcd.print("Current value:");
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);     
  lcd.setCursor(0, 1);
  lcd.print(sensorValue /4);
  lcd.print("/255 ");

What I have tried:

I managed to establish a connection between c# and arduino but to read the values from the potenciometer and bring them onto the line is what I struggle.
Updated 29-May-16 14:25pm
Sergey Alexandrovich Kryukov 29-May-16 14:41pm    
Unfortunately, it looks like a lot of information is missing. I would suggest you through out the idea "I'm very bad at explaining" and do it good. No high art is required of you; you just need to take some patience and just explain it step by step, not skipping anything. First of all, better totally skip WPF part; it does not matter how you do UI; focus on communication between PC and Arduino. What is that "between C# (WPF) and Arduino"? First, you connect, PC and Arduino hardware. How? USB? Serial? Ethernet? It's all possible, but you did not write a word about it. Formulate your goal. It looks clear that you control LCD from Audrino and can display data. Do you want to use PC instead of LCD, in other words, output some readings depending on potentiometer position on your PC? You can...
Member 12553290 29-May-16 15:34pm    
I have my Arduino connected to the PC via USB cabel. The way it works is quite simple and it's based off of the LiquidCrystal Example (code and sheme) that I found on the official Arduino website. Connecting the potenciometer onto the Analog pin A0 I can change the value, which usually goes to max. 1023 but I chnaged it to 255, of it and displaying it on the LCD screen. My task was to create a line, which I already have. My current task is: Use the potenciometer to change the value of it and how I'm changing it, the change is transfered to the line. I guess you can say that it works in sync. If the current value is 0, the line must be on its lowest value too, if it's max value, the line must be on its may value. This project that I'm working is basically a speedometer. If it's still not understandable, please ask.
Sergey Alexandrovich Kryukov 29-May-16 16:56pm    
Sergey Alexandrovich Kryukov 29-May-16 16:58pm    
Better. Thank you for the clarification.
USB connection makes the problem a lot more difficult. I don't know (yet) what could be used on Arduino side.
On PC side, there are such wonderful open-source products as libusb and LibUsbDotNet.
Member 12553290 29-May-16 17:50pm    
Oh, maybe I'm mistaken. the arduino is connected to the pc via USB, yes, but that's for the power so it can work (turn on). Isn't the connection beetween serial though?

You are well on the way. All you need next is in this article. Of course you are using Arduino and not PIC. Use the example as a template for your solution.

Serial Communication using WPF, RS232 and PIC Communication[^]
Share this answer
Please see my comments to the question.

For PC side, Windows with .NET, please see the open-source projects libusb and LibUsbDotNet:

On Arduino side, you can start here: Arduino — SoftwareSerial.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900