Change mblock firmware to enable internal pullup resistor for input


#1

Hi there,

For a small minimalistic education project for kids i want to use a switch as input without using a pull-up resistor on my arduino Nano.

When coding using the Arduino IDE, the internal pull-up resistor can be enabled with ‘pinMode(5,INPUT_PULLUP);’ in the setup function.

I succeeded to enable the pull-up resistor for digital inputs in MBlock my modifying the Arduino.s2e in the mBlock package (Contents/Resources/ext/libraries/arduino/Arduino.s2e) by changing

	["B", "read digital pin %n","getDigital","9",
	{"encode":"{d0}","setup":"pinMode({0},INPUT);\n","inc":"","def":"","work":"digitalRead({0})","loop":""}],

Into

	["B", "read digital pin %n","getDigital","9",
	{"encode":"{d0}","setup":"pinMode({0},INPUT_PULLUP);\n","inc":"","def":"","work":"digitalRead({0})","loop":""}],

When running a Scratch script as an Arduino Program, the internal pull-up resistor is enabled and the status of the switch can be read properly.

If the same program is run as a Scratch application using the mBlock firmware on the Arduino, the status of the switch changes due to the noise on the input pin. I tried to fix this by changing the baseboard_firmware.ino and changed in function runModule the case DIGITAL from pinMode(pin,INPUT); to pinMode(pin,INPUT_PULLUP); and repeated this in the function readSensor.

But as you can expect i failed to get this working properly. The value on the input is still not stable, so probably the pull-up resistor is not enabled.

Any suggestions ?

Cheers,
Peter


#2

Hello! I have found the way. The thing that happens when you change the code in baseboard.ino, or now in new version: “orion.ino” (where button “Connect”–>“View Source” targets) is that mblock does not use that code when you run “Upgrade Firmware”. Instead, it somehow uses old code, even though now View Source shows changed code.

SOLUTION:
I have opened Arduino IDE from mBlock and copy pasted code from Vies Source (your edited baseboard.h) and voila. It works as a charm. I have then closed and opened mblock and it worked.

I have tried to upload again directly with Upgrade Firmware button and again it didn’t worked. So mBlock uses code from strange source…

Hope it helps.

Good luck!