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