Skip to content

Arduino IDE 2.0 problem with ESP32-CAM-MB and Module CH340G #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
Erhie opened this issue May 20, 2022 · 21 comments
Closed
3 tasks done

Arduino IDE 2.0 problem with ESP32-CAM-MB and Module CH340G #17

Erhie opened this issue May 20, 2022 · 21 comments
Assignees
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project

Comments

@Erhie
Copy link

Erhie commented May 20, 2022

Describe the problem

No output in Serial Monitor using Arduino IDE 2.0 RC6 on Windows 10 with ESP32-CAM and CH340G

Because there are some pictures the detailed description in a Google Docs:
[Arduino IDE 2.0 problem with Serial monitor - Google Docs 2]

Discussion with ptillisch and also tests with CLI nightly build https://downloads.arduino.cc/arduino-cli/nightly/arduino-cli_nightly-latest_Windows_64bit.zip don't solve the problem.

To reproduce

Plug USB and according the sketch the LED blinks
starting the command ./arduino-cli.exe monitor -p COM5
The led is dark and the message is
Connected to COM5! Press CTRL-C to exit
no output is logged.

starting the command with unplugged USB
and plug USB few seconds after the message is

Connected to COM5! Press CTRL-C to exit.
��f������`���

and the led is dark.

With same sketch and
Arduino 1.8.16 after press reset on ESP board:

20:24:35.642 -> 9Zv⸮c/a{)a5⸮⸮⸮V:⸮aQVHhello #0
20:24:37.143 -> hello #1
20:24:37.658 -> hello #2
20:24:38.128 -> hello #3
20:24:38.641 -> hello #4
20:24:39.153 -> hello #5
20:24:39.622 -> hello #6
20:24:40.136 -> hello #7
20:24:40.648 -> hello #8
20:24:41.159 -> hello #9
20:24:41.625 -> hello #10
20:24:42.138 -> hello #11

and led blinks

Expected behavior

to have the same output as on Arduino 1.8.16

serial-monitor version

arduino-cli.exe Version: nightly-20220519 Commit: 6883b39 Date: 2022-05-19T01:34:16Z

Operating system

Windows

Operating system version

10 Pro 21H2

Additional context

please implement the behavior on Arduino 2.0 as on Arduino 1.8.16

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest version
  • My report contains all necessary details
@Erhie Erhie added the type: imperfection Perceived defect in any part of project label May 20, 2022
@cmaglie
Copy link
Member

cmaglie commented May 24, 2022

Hi @Erhie !

I've read the discussion on the forum, it's a really bad issue.

I'd like to send you a small terminal program written in golang to try out, to further reduce the possible causes. May you compile a golang program in case?
Otherwise I can post here a prebuild executable if you're ok with that.

@cmaglie
Copy link
Member

cmaglie commented May 24, 2022

package main

import (
	"fmt"
	"os"
	"strconv"

	"go.bug.st/serial"
)

func usage() {
	fmt.Println("Usage: term <PORT> [baudrate]")
	os.Exit(1)
}

func main() {
	args := os.Args[1:]
	if len(args) == 0 {
		usage()
	}
	portname, args := args[0], args[1:]
	baudrate := 9600
	if len(args) > 0 {
		if b, err := strconv.Atoi(args[0]); err != nil {
			fmt.Println("Invalid baudrate:", args[0])
			os.Exit(1)
		} else {
			baudrate = b
		}
		args = args[1:]
	}
	if len(args) > 0 {
		usage()
	}

	port, err := serial.Open(portname, &serial.Mode{BaudRate: baudrate})
	if err != nil {
		fmt.Printf("Error opening serial port %s: %s\n", portname, err)
		os.Exit(2)
	}

	var buff [1024]byte
	for {
		n, err := port.Read(buff[:])
		if err != nil {
			fmt.Println("Error reading from serial port:", err)
			break
		}
		if n == 0 {
			fmt.Println("Timeout reading from serial port.")
			continue
		}
		os.Stdout.Write(buff[:n])
	}

	port.Close()
}

ok this is the program, it should be run like this:

C:\> go run main.go COM1
Connected to COM1
16814
16815
16816
16817
16818
16819
16820
16821  <--- this is the output from my board
16822
16823
16824
16825
16826
16827

Otherwise you can use this precompiled term.exe, you should run it the same:

C:\> term.exe COM1
Connected to COM1
16814
16815
16816
16817
16818
16819
16820
...

@cmaglie cmaglie self-assigned this May 24, 2022
@cmaglie
Copy link
Member

cmaglie commented May 31, 2022

I've been looking at the Arduino IDE 1.8.x source code and I see that the IDE is explicitly setting RTS/CTS:

https://github.com/arduino/Arduino/blob/43b0818f7fa8073301db1b80ac832b7b7596b828/arduino-core/src/processing/app/Serial.java#L81-L87

On the IDE 1.8 they are always enabled (unless specified otherwise), instead on the IDE 2.0/CLI they are left "untouched". It may be that the board you're using requires an explicit activation of those bits, something to try out.

@ubidefeo ubidefeo added the status: waiting for information More information must be provided before work can proceed label Aug 5, 2022
@ubidefeo
Copy link

ubidefeo commented Aug 5, 2022

@Erhie
have you had any chance to follow up on testing?

@Erhie
Copy link
Author

Erhie commented Aug 6, 2022

at last I use Arduino IDE 1.8.19 and forgot IDE 2.0

@Erhie
Copy link
Author

Erhie commented Aug 8, 2022

now I test IDE 2.0 rc9.1
with the script below, but have no output in serial monitor
with IDE 1.8.19 it works fine

int i = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  // Serial.setDebugOutput(true); uncommented by OpaErhard
  Serial.println();
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(i++);
}

@per1234
Copy link
Contributor

per1234 commented Aug 8, 2022

Thanks @Erhie. Are you able to run the test that was requested above at this comment?

#17 (comment)

Please let us know if you have any questions or problems.

@Erhie
Copy link
Author

Erhie commented Aug 9, 2022

sorry, I have problems with Go

with VS code
Build Error: go build -o h:\Users\gle\Documents\Arduino__debug_bin.exe -gcflags all=-N -l .
package example.com/m: C source files not allowed when not using cgo or SWIG: led.c

don't know how to fix it because all helps are for Linux alike

@per1234 per1234 removed the status: waiting for information More information must be provided before work can proceed label Aug 10, 2022
@per1234
Copy link
Contributor

per1234 commented Aug 10, 2022

It seems you have a file named led.c in the same folder as the Go program. You must remove any unnecessary files from the folder.

I'll provide complete instructions (omitting installation of Go since I can see you already have it):

  1. Start the Arduino IDE.
  2. Connect your ESP32-CAM-MB board to your computer as usual.
  3. Upload a sketch to the ESP32-CAM-MB board that periodically prints to serial at 9600 baud:
    int i = 0;
    void setup() {
      Serial.begin(9600);
    }
    void loop() {
      Serial.println(i++);
      delay(1000);
    }
  4. Select Tools > Port from the Arduino IDE menus.
  5. Note which serial port your ESP32-CAM-MB board is on.
  6. Select File > Quit from the Arduino IDE menus.
  7. Hover the mouse pointer over the box below. You will see an icon appear at the top right corner. Click that icon to copy the code to the clipboard.
    package main
    
    import (
    	"fmt"
    	"os"
    	"strconv"
    
    	"go.bug.st/serial"
    )
    
    func usage() {
    	fmt.Println("Usage: term <PORT> [baudrate]")
    	os.Exit(1)
    }
    
    func main() {
    	args := os.Args[1:]
    	if len(args) == 0 {
    		usage()
    	}
    	portname, args := args[0], args[1:]
    	baudrate := 9600
    	if len(args) > 0 {
    		if b, err := strconv.Atoi(args[0]); err != nil {
    			fmt.Println("Invalid baudrate:", args[0])
    			os.Exit(1)
    		} else {
    			baudrate = b
    		}
    		args = args[1:]
    	}
    	if len(args) > 0 {
    		usage()
    	}
    
    	port, err := serial.Open(portname, &serial.Mode{BaudRate: baudrate})
    	if err != nil {
    		fmt.Printf("Error opening serial port %s: %s\n", portname, err)
    		os.Exit(2)
    	}
    
    	var buff [1024]byte
    	for {
    		n, err := port.Read(buff[:])
    		if err != nil {
    			fmt.Println("Error reading from serial port:", err)
    			break
    		}
    		if n == 0 {
    			fmt.Println("Timeout reading from serial port.")
    			continue
    		}
    		os.Stdout.Write(buff[:n])
    	}
    
    	port.Close()
    }
  8. Create a new folder.
    The folder can be at any convenient location and with any name you like.
  9. Create a file in the folder with the name main.go
  10. Paste the code you copied at step (6) into the file main.go
  11. Save the file.
  12. Open a terminal at the folder path.
    You can use any terminal you prefer (e.g., PowerShell, Command Prompt, cmd, Bash)
  13. Run the following command from the terminal to initialize the Go project:
    go mod init example.com/foo
    
  14. Run the following command from the terminal to install the dependencies of the project:
    go get
    
  15. Run the following command from the terminal to run the Go program:
    go run main.go <port>
    
    ❗ Replace <port> in the command above with the serial port of your ESP32-CAM-MB board, as determined at step (4) of the instructions (e.g., go run main.go COM7).

Please let me know if you have any questions or problems while following those instructions.

After executing the go run command, the expected behavior is to start seeing numbers printed to the terminal window at 1 Hz. Please let us know whether that happens.

Once you are finished, you can exit the program by pressing Ctrl+C.


If you prefer, you can also try the executable provided by @cmaglie in the previous reply:

Otherwise you can use this precompiled term.exe, you should run it the same:

Unfortunately, Windows Defender was not happy about the file when I downloaded it to my computer, so it is possible you will have difficulty with that approach as well, but maybe worth a try if building the program from source is not convenient?

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Aug 10, 2022
@Erhie
Copy link
Author

Erhie commented Aug 10, 2022

Thank you for your patience with me.
Sorry,
with Select File > Quit from the Arduino IDE menus
Arduino IDE exits and no possibility to over the mouse pointer over the box below

@per1234
Copy link
Contributor

per1234 commented Aug 10, 2022

Thank you for your patience with me.

You are welcome.

Thanks to you for assisting us with this investigation.

no possibility to over the mouse pointer over the box below

The box is in my previous reply here on GitHub:

image

@Erhie
Copy link
Author

Erhie commented Aug 10, 2022

now:

PS H:\Users\gle\Documents\ArduinoGo> go get
example.com/foo imports
        fmt: package fmt is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\fmt)
example.com/foo imports
        os: package os is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\os)
example.com/foo imports
        strconv: package strconv is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\strconv)
example.com/foo imports
        go.bug.st/serial imports
        sync: package sync is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\sync)
example.com/foo imports
        go.bug.st/serial imports
        syscall: package syscall is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\syscall)
example.com/foo imports
        go.bug.st/serial imports
        time: package time is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\time)
example.com/foo imports
        go.bug.st/serial imports
        unsafe: package unsafe is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\unsafe)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        bytes: package bytes is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\bytes)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        errors: package errors is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\errors)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        net: package net is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\net)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        runtime: package runtime is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\runtime)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        strings: package strings is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\strings)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        sync/atomic: package sync/atomic is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\sync\atomic)
example.com/foo imports
        go.bug.st/serial imports
        golang.org/x/sys/windows imports
        unicode/utf16: package unicode/utf16 is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\unicode\utf16)

PS H:\Users\gle\Documents\ArduinoGo> go run main.go COM5
main.go:4:2: package fmt is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\fmt)

@cmaglie
Copy link
Member

cmaglie commented Aug 10, 2022

Hi @Erhie,

maybe it's more simple if you get the zip here -> term.zip
It contains a term folder with the go test code already written, you just need to open a command propmt and execute

go run main.go COM5

from the `term' folder.

@Erhie
Copy link
Author

Erhie commented Aug 11, 2022

sorry, more packages are need:

PS H:\Users\gle\Documents\ArduinoGo2\term> go run main.go COM5
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\syscall.go:28:2: package bytes is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\bytes)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\exec_windows.go:10:2: package errors is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\errors)
main.go:4:2: package fmt is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\fmt)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\types_windows.go:8:2: package net is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\net)
main.go:5:2: package os is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\os)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\syscall_windows.go:12:2: package runtime is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\runtime)
main.go:6:2: package strconv is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\strconv)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\syscall.go:29:2: package strings is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\strings)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\dll_windows.go:8:2: package sync is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\sync)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\dll_windows.go:9:2: package sync/atomic is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\sync\atomic)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\aliases.go:10:8: package syscall is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\syscall)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\syscall_windows.go:15:2: package time is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\time)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\windows\syscall_windows.go:16:2: package unicode/utf16 is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\unicode\utf16)
C:\Users\gle\go\pkg\mod\golang.org\x\[email protected]\internal\unsafeheader\unsafeheader.go:14:2: package unsafe is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\unsafe)

@cmaglie
Copy link
Member

cmaglie commented Aug 11, 2022

package unicode/utf16 is not in GOROOT (C:\Users\gle\scoop\apps\go\current\src\unicode\utf16)

The package unicode/utf16 should be part of the golang system libraries (same for all the other missing packages).
Are you sure that your installation of go is good?

@Erhie
Copy link
Author

Erhie commented Aug 11, 2022

I just managed it.
I had many Go installations, so I uninstalled all
and purged all set variables for them and the path entries for them.
I installed Go for Windows with go1.19.windows-amd64.msi
And add a new path entry to C:\Program Files\Go\bin .
Started powershell again that the prompt shows our path H:\Users\gle\Documents\ArduinoGo2\term

go build reports

go: downloading go.bug.st/serial v1.3.5
go: downloading golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf

On my ESP32-cam board I loaded the sketch

int i = 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.println(i++);
  delay(1000);
}

and the serial monitor of IDE 1.8.19 shows the expected output.
After quitting the IDE
In Powershell again

go run main.go COM5

it runs, but see no output

@cmaglie
Copy link
Member

cmaglie commented Aug 11, 2022

ok could you try this variant:

package main

import (
	"fmt"
	"os"
	"strconv"

	"go.bug.st/serial"
)

func usage() {
	fmt.Println("Usage: term <PORT> [baudrate]")
	os.Exit(1)
}

func main() {
	args := os.Args[1:]
	if len(args) == 0 {
		usage()
	}
	portname, args := args[0], args[1:]
	baudrate := 9600
	if len(args) > 0 {
		if b, err := strconv.Atoi(args[0]); err != nil {
			fmt.Println("Invalid baudrate:", args[0])
			os.Exit(1)
		} else {
			baudrate = b
		}
		args = args[1:]
	}
	if len(args) > 0 {
		usage()
	}

	port, err := serial.Open(portname, &serial.Mode{BaudRate: baudrate})
	if err != nil {
		fmt.Printf("Error opening serial port %s: %s\n", portname, err)
		os.Exit(2)
	}

	port.SetDTR(true)  // <-----------------
	port.SetRTS(true)  // <-----------------

	var buff [1024]byte
	for {
		n, err := port.Read(buff[:])
		if err != nil {
			fmt.Println("Error reading from serial port:", err)
			break
		}
		if n == 0 {
			fmt.Println("Timeout reading from serial port.")
			continue
		}
		os.Stdout.Write(buff[:n])
	}

	port.Close()
}

I've added the two lines marked with the arrows:

	port.SetDTR(true)  // <-----------------
	port.SetRTS(true)  // <-----------------

that sets the DTR and RTS bits of the port. It's the only difference I found with the Arduino IDE 1.8.x.
I'd like to ask you to try all the four different combinations:

DTR RTS Result
true true .....
true false
false true
false false

I hope that this unlocks something, otherwise, I'm out of ideas...

@Erhie
Copy link
Author

Erhie commented Aug 11, 2022

it seems that false, false is promising.

	/*
	port.SetDTR(true)  // <-----------------
	port.SetRTS(true)  // <-----------------
	nothing to see */
	/* 
	port.SetDTR(false)  // <-----------------
	port.SetRTS(false)  // <-----------------
	restarts esp32 and this in output
�Q�6��\:�q�}���c ��Q%�0
1
2
3
4
	*/
	/*
	port.SetDTR(true)  // <-----------------
	port.SetRTS(false)  // <-----------------
	this in output
���0�.�Z�Z
	*/
	port.SetDTR(false)  // <-----------------
	port.SetRTS(true)  // <-----------------
	/* nothing to see */

@cmaglie
Copy link
Member

cmaglie commented Sep 21, 2022

@Erhie
we just published an update to the serial-monitor to account for RTS/DTR signals.
Could you retry with the latest Arduino IDE 2.0.0? it should now automatically download and update the serial-monitor tool.

@umbynos
Copy link
Contributor

umbynos commented Oct 17, 2022

Hey @Erhie do you find the time to check it out? 😄

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Nov 6, 2022
@cmaglie
Copy link
Member

cmaglie commented Dec 1, 2022

I'm closing this as fixed.

@Erhie if the issue is not fixed for you feel free to re-open.

@cmaglie cmaglie closed this as completed Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for information More information must be provided before work can proceed type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

5 participants