Flashing code to Arduino Uno using Make on Ubuntu on WSL

So, I'm working on a project that requires me to be able to upload C code to my arduino without using the arduino IDE (I've been informed that this is called flashing, unless I'm completely mistaken). I have the example code (just a simple blink function written in C) and a makefile, which I think I have a grasp on how to use but I could also be wrong. This makefile has some functions, which I will include below, and a list of things above those functions that look a lot like variables to me, though I suppose I might not be the most informed on makefiles. Anyway, compile works just fine, but upload has a problem because I can't for the life of me figure out what to put down for Port. I have an Uno connected to COM4 on my windows laptop, but I'm using (what I believe is) an Ubuntu image hosted on WSL, and no matter what I try I can't seem to get the makefile to see the board. I know that it's a user error, I just don't know how to correct it.

I have tried:
4
COM4
com4
/dev/COM4

and none of these are the answer. Can somebody help me out?

Thank you in advance.

If you were curious, that makefile code is:

.

FILENAME = blink

#! this will change depending on your system
PORT = /dev/com4 # serial port that the board is connected to

DEVICE = atmega328p # which microcontroller is on the board (usually ATMEGA328P for arduino)
PROGRAMMER = arduino # which bootloader to use
BAUD = 115200 # speed of communication to the board

CC = avr-gcc
CFLAGS = -Wall -Os -mmcu=$(DEVICE)
# -Wall: enables warnings
# -Os: optimizes the code for size (uses optimizations from O2 that don't increase size)
# -mmcu: specifies the architecture of the board

.PHONY: compile
compile: ## compiles the C code to a hex file
$(CC) $(CFLAGS) -c $(FILENAME).c -o $(FILENAME).o $(CC) $(CFLAGS) -o $(FILENAME).elf $(FILENAME).o avr-objcopy -j .text -j .data -O ihex $(FILENAME).elf $(FILENAME).hex

.PHONY: upload
upload: ## flashes hex file to the board
avrdude -v -p $(DEVICE) -c $(PROGRAMMER) -P $(PORT) -b $(BAUD) -U flash:w:$(FILENAME).hex:i

.PHONY: update
update: compile upload ## compiles and uploads, updating code on the board

.PHONY: clean
clean: ## deletes ELF, object, and hex files (doesn't work well with Windows)
/bin/rm -f core.* *.o *.elf *.hex

help: ## show this help (does NOT work on Windows, due to egrep and awk)
@egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

look under /dev to see which devices exist with and without the cable plugged in

I'm currently looking under /dev, and there seems to be no difference in the results when i have the cord plugged in or not. All I have is:

autofs         cpu_dma_latency  kmsg          loop3  mapper  ppp   ram10  ram15  ram6    rtc0  shm     tty0   tty13  tty18  tty22  tty27  tty31  tty36  tty40  tty45  tty5   tty54  tty59  tty63  ttyS1    vcs1   vfio
block          cuse             loop-control  loop4  mem     ptmx  ram11  ram2   ram7    sda   stderr  tty1   tty14  tty19  tty23  tty28  tty32  tty37  tty41  tty46  tty50  tty55  tty6   tty7   ttyS2    vcsa   vhost-net
bsg            fd               loop0         loop5  net     pts   ram12  ram3   ram8    sdb   stdin   tty10  tty15  tty2   tty24  tty29  tty33  tty38  tty42  tty47  tty51  tty56  tty60  tty8   ttyS3    vcsa1  vsock
btrfs-control  full             loop1         loop6  null    ram0  ram13  ram4   ram9    sg0   stdout  tty11  tty16  tty20  tty25  tty3   tty34  tty39  tty43  tty48  tty52  tty57  tty61  tty9   urandom  vcsu   zero
console        fuse             loop2         loop7  nvram   ram1  ram14  ram5   random  sg1   tty     tty12  tty17  tty21  tty26  tty30  tty35  tty4   tty44  tty49  tty53  tty58  tty62  ttyS0  vcs      vcsu1

Any ideas?

using cygwin on windows, i see ttyS3 only when the Arduino is attached.

It looks like I have ttyS3 both when the arduino is and is not attached. I went back into the makefile and changed the Port to /dev/ttyS3, to which I received the message

avrdude: ser_open(): can't open device "/dev/ttyS3": Permission denied

So, I ran sudo make upload thinking that that would take care of my permission issue, and I received

avrdude: ser_open(): can't set attributes for device "/dev/ttyS3": Inappropriate ioctl for device

instead.

Thank you for taking the time to help me out with this, especially with the running it on your end. I really appreciate it.

bear in mind i'm using cygwin, not linux/ubuntu

perhaps you can just try to "cat" from one of those file to find the one that is active

why can't you install the Arduino IDE for Ubuntu?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.