Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I'm trying to make a program that have to upload an Arduino file (.ino) by pressing a button on windows forms. I looked how to do it and I found that there is a package "ArduinoUploader", but I think I didn't understand how to use it. It give me this error when I press the button "System.NullReferenceException: 'Reference to an object not set to an object instance.'".
Please I need help to fix it. Thanks.

What I have tried:

C#
using ArduinoUploader;
using ArduinoUploader.Hardware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

    private void SelectProgramButton_Click(object sender, EventArgs e)
    {
        var uploader = new ArduinoSketchUploader(
        new ArduinoSketchUploaderOptions()
        {
            FileName = @"C:\Users\.....\Desktop\cscharp\.....\.....\TEST.ino",
            PortName = "COM3",
            ArduinoModel = ArduinoModel.Mega2560
        });
        uploader.UploadSketch();
    }
Posted
Updated 14-May-21 1:07am
v2

One of the variables in the above code is null. You will need to use your debugger to find out which one and why. It is not something that anyone here can do for you.
 
Share this answer
 
Maybe the specified serial port (COM3) is not available on your PC.
You should specify the valid port (or omit it, as pointed out here: GitHub - twinearthsoftware/ArduinoSketchUploader: A .NET library and a command line utility to upload a compiled sketch (. HEX file) directly to an Arduino board.[^]).
 
Share this answer
 
Comments
Member 14786879 14-May-21 6:33am    
The serial port is correct, it is COM3 connected to my Arduino Mega 2560
CPallini 14-May-21 6:50am    
Could you, please, report the full exact error message?
Member 14786879 14-May-21 7:05am    
I solved the problem, I was not pointing the .hex file. My bad. Thank you anyway.
CPallini 14-May-21 7:19am    
You are welcome.
using ArduinoUploader;
using ArduinoUploader.Hardware;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

    private void SelectProgramButton_Click(object sender, EventArgs e)
    {
        var uploader = new ArduinoSketchUploader(
        new ArduinoSketchUploaderOptions()
        {
            FileName = @"C:\Users\.....\Desktop\cscharp\.....\.....\TEST.ino.mega.hex",
            PortName = "COM3",
            ArduinoModel = ArduinoModel.Mega2560
        });
        uploader.UploadSketch();
    }
 
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