[ERROR] All buttons of PlatformIO for VS Code on Ubuntu is disable

PS. I’m on Linux Mint 19.3 which is Ubuntu based.

Screenshot-from-2020-08-22-08-53-19

Not quite… exactly as follows:

echo $SHELL

(which will print (echo)the contents of the variable ($) named SHELL), which looks to be bash, judging from the screenshot.

image

So there is no response or errors from the buttons being pressed at all? The PlatformIO extention clearly knows it should be activated for the project, otherwise only the first icon, the PIO Home icon, would be shown on the statusbar.

It may be worth opening the developer tools console (Help → Toggle Developer Tools, and select the ‘Console’ tab if it isn’t already selected) and seeing if there are any errors reported when you click the Build button. You can also try Ctrl+Shift+B, or the build option under the PlatformIO sidebar panel:
image

Screenshot-from-2020-08-22-10-00-04

RIGHT, there are so many errors here.

“exited with error code 127”

I thought it was because I have created the projects into an error folder, so I made a new one, and deleted the last projects. Now, this is the prompt:

Screenshot-from-2020-08-22-10-22-54

Sorry but I’m not able to read the text on your screenshots I’m afraid. They are blurred when I open them (on my tablet) on the web page and do not scroll or resize on that page (imgbb) - weird. (Mind you, I have Javascript disabled for most web pages on my tablet!)

If I open the image, from the imgbb web page, they are tiny, and impossible to read.

If you need to post code or error text, just copy it please, when pasting into a reply, type three backticks on a separate line, paste the code, the three more backtick. Like this:

```
Paste your error text or code here.
```

It’s easier than using an online image “thing” which seems to minimize your screeshots.

Cheers,
Norm.

[Extension Host] Congratulations, your extension "code-gnu-global" is now active!
2console.ts:137 [Extension Host] Command: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp" running...
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
console.ts:137 [Extension Host] activating extension
console.ts:137 [Extension Host] starting language server
console.ts:137 [Extension Host] Command: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp" running...
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
2console.ts:137 [Extension Host] (node:2753) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log @ console.ts:137
console.ts:137 [Extension Host] runCommand platformio Array(1) Object
console.ts:137 [Extension Host] Command: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp" running...
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
console.ts:137 [Extension Host] Command: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp" running...
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
console.ts:137 [Extension Host] Command: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp" running...
console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)
t.log @ console.ts:137
console.ts:137 [Extension Host] undefined
notificationsAlerts.ts:40 Extensions have been modified on disk. Please reload the window.
onDidChangeNotification @ notificationsAlerts.ts:40
console.ts:137 [Extension Host] Found PIO Core 4.3.4
1 Like

The errors were in red, but when I pasted them, they lost red color:

console.ts:137 [Extension Host] Error: Error: Command failed: global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"/bin/sh: 1: global: not found `global --encode-path " " -f "/home/mq/UNOprojects/demo_LM75/src/main.cpp"` (exited with error code 127)

Is this clear ?

I am clutching at straws here, as I don’t know what is causing that

error, but do you have any other extensions installed on VSCode? And how did you install VSCode - is it running nativly, or via a Snap package? As I seem to remember hearing that VSCode was acting weirdly in Snap (or was it Flatpak? :open_mouth: ).

Thanks.

Losing the red colour is not a problem, trust me. Your pasted screenshot is perfectly clear.

I’m puzzled by the “global” command. I don’t recall seeing it before. Hmmm. Unless it’s to do with the message your extension “code-gnu-global” is now active at the start.

[Insert quick google search here]

Ok, that is a C++ extension for VSCode, amongst others. I don’t recall it being needed by PlatformIO - but happy to be corrected. I wonder if it is interfering.

Do the buttons work if you disable that extension? You might need to restart the editor, I’m not sure.

Cheers,
Norm.

It might be that. I’m not remember clearly.

I installed only these 3 extensions, when I installed Arduino extension just now, VS Code prompted there was an extension conflict, ant when I selected the suggestion, it uninstalled Arduino.

Here, I found the “global”:

I uninstalled it, it was the same, so maybe I need to reinstall VS Code, this time not via SNAP.

Hmm, snap. I believe that does cause problems.

Beware! I’m also told that when you apt get on Ubuntu to install some stuff, it sneakily uses snap instead. I’m on Linux Mint which doesn’t like/use snaps.

I suspect for VSCode, you can download a *.deb file and install it with apt or dpkg. Good luck.

Cheers,
Norm.

1 Like

Yes, it was it. I removed VS Code and installed it again, I then installed Arduino extension first and verified and uploaded blink.ino, it was OK. Since it was prompted that there was conflict between Arduino extension and PlatformIO extension, so I uninstalled the previous one and installed the latter one, this time, for ensuring it was really work, I modified the blink.ino file and it was also verified and uploaded.

Where I found the installation and uninstall method were here:

  1. uninstall:
    software center - How do I uninstall Visual Studio Code? - Ask Ubuntu
  2. install:
    https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-20-04/

[IMPORTANT]Notes:
1.Don’t use snap method, use apt method.
2.After I uninstalled VS Code and installed it by the apt method immediately, the extension I installed before removal was already there, so I made a reboot between uninstall and install.
3.When I still couldn’t built project, I opened a new terminate, and “mkdir → cd → code”, then “creat a new project” in PlatformIO.

1 Like

Whats more, I modified the Arduino blink.ino, since I don’t want to use its delay() function, but the LED blinked not evenly, that means sometimes, there was longer darkness and brightness than other duration.

Anyone here advice?

Since I could only upload image now, so I add the code here, one could download into locale for viewing:

#include <Arduino.h>

unsigned long duration = 1000;
unsigned long durationDark = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  if(millis() - duration >= 1000) {
    digitalWrite(13, HIGH);
    duration = millis();
  }

  if(millis() - durationDark >= 1000) {
    digitalWrite(13, LOW);
    durationDark = millis();
  }

I’m glad you got your buttons fixed. Looks liks snap is best avoided!

Your code is possibly suffering from interrupts. I think. The data types you are holding your durations in are long but the ATmega328 is byte sized and doesn’t have 16 or 32 bit instructions as such.

Millis() turns interrupts off to update its long variables, as it is done within the ISR for Timer/counter 0’s Overflow Interrupt. That allows the update to work correctly.

Your updates to the duration generate code to update 4 bytes from a value that is 4 bytes long. Between each byte, in interrupt can occur, changing the values in the bytes not yet copied over to your variables.

Try adding noInterrupts(); before, and interrupts(); after, your assignments from millis() to your duration variables.

I think that will solve those problems.

You are aware that millis() will roll over at some point? That will affect things too. It leads to long periods of darnkess or light! (Rollover happens every 2^32 + 1 milliseconds.)

Cheers,
Norm.

1 Like

ok, i will try it. :watermelon:

Hi @mianqi,

sorry, I was wrong! Don’t bother. While I wa correct that interrupts could be a problem, they are not because whenever you call millis() interrupts are off while the 4 bytes are transferred:

unsigned long millis()
{
	unsigned long m;
	uint8_t oldSREG = SREG;
 37c:	2f b7       	in	r18, 0x3f	; 63

	// disable interrupts while we read timer0_millis or we might get an
	// inconsistent value (e.g. in the middle of a write to timer0_millis)
	cli();
 37e:	f8 94       	cli
	m = timer0_millis;
 380:	80 91 09 01 	lds	r24, 0x0109	; 0x800109 <timer0_millis>
 384:	90 91 0a 01 	lds	r25, 0x010A	; 0x80010a <timer0_millis+0x1>
 388:	a0 91 0b 01 	lds	r26, 0x010B	; 0x80010b <timer0_millis+0x2>
 38c:	b0 91 0c 01 	lds	r27, 0x010C	; 0x80010c <timer0_millis+0x3>
	SREG = oldSREG;

That’s the assembly code generated for the code in the millis() function which fetches the value of timer_0_millis into a variable named m ready to be returned. You can see a cli instruction above the fetching of 4 bytes in 4 separate instructions. The SREG = oldSREG is where the interrupts are enabled again - assuming they were before they were turned off.

False alarm, sorry!

The problem looks to be in your code. There is an example of using millis() rather than delay() on the Arduino web at https://www.arduino.cc/en/tutorial/BlinkWithoutDelay which does work. Maybe you can study that code and see what’s different from yours?

You are pulling the millis() value twice, well 4 times, in loop() and each one will be very different. The value increments 1,000 times every second, so even a short time between getting the value and using it will cause it to be different, then when you assign the value to one of the duration variable, it will have moved on again.

You need to grab millis() when you enter the loop, every time. You should, I think, also be holding the previous time that you toggled the LED. You can then check that millis (now) - millis(then) > duration to determine if it’s time that the LED was toggled. That’s what the Arduino example does.

HTH

Cheers,
Norm.

1 Like

Got it. :watermelon: