Read analog pin (A) does not read values with Arduino Uno


#1

When I try to read values with mBlock I get nothing

But it works with Arduino IDE


#2

Seems to work ok for me @EduL. I tried a simple program with a little UNO/shield combination I’ve got where I have a potentiometer hooked to A5, and an LED hooked to pin 5 (i.e. one of the PWM pins). (As there’s no way I see to read variable values in mBlock Arduino mode, I had to have a way to display the analog value I read, therefore the PWM/LED).

Here’s the program … (I scaled the 0 - 1023 input level to drive the PWM).

Here’s the corresponding Arduino code generated by mBlock …

What have you tried that isn’t working?


#4

Hi Larry, I try to to this

And this is the program

But does not work in mBlock

If I generate the code

It works very well

I hope you can help me


#5

Hi @EduLibre - I am not totally certain, but think you might be trying to operate in a mode that is not supported. Per my understanding, I do not think you can load/run ‘when Flag clicked’ programs onto an Arduino board. I think this program variant can only be used with one of the MakeBlock boards - Orion, mCore, etc. (The documentation is a bit confusing as I do recall seeing one part of a video that appeared to suggest you could load onto an Arduino UNO, but I do not think this is the case).

I’ve used Arduino mode to load ‘Arduino Programs’ and 'mBot Programs (see below) onto an UNO. I tried your ‘when Flag clicked’ example though and got the same results you did … but again, I’m not sure if this mode is supposed to work.

(This works fine … )

(I could be wrong or misunderstanding something myself here … if so, hopefully someone will jump in and set things straight).

Just curious - is there a particular reason you’re trying to get that ‘Flag clicked’ version to work?


#6

Further to my previous post - perhaps there is some firmware that needs to be first loaded onto the UNO to support that Flag clicked mode … I’ll look around to see if this might be the case and if I can find anything. (Not saying there is, just considering the possibility).


#7

Ok @EduLibre, I think you can disregard my first post. Taking a clue from @danjger on this thread, you can indeed ‘Upgrade Firmware’ on your UNO to allow it to communicate and respond to ‘Flag clicked’ programs. Just go to Connect > Upgrade Firmware in mBlock with your UNO connected. Your program should then run fine.

Sorry for my earlier misleading post. My response was premature … I should have searched further first.


#8

Larry, upgrade the firmware is not the solution, but thanks for your help.

With regard to your question about the reason for using the green flag,
first of all, I’m from Mexico and teach Scratch to children 9 - 12 years,
I am now interested in introducing Arduino, and I think MBLOCK is a good choice.
One of the first activities is to work with LEDs and after understanding the functions of the sensors.
I think it is easier to understand these concepts if they first work with the IDE MBLOCK.


#9

Hmmm … not sure what the problem is @EduLibre. I just tried it with another UNO board I had, and everything works fine in ‘Flag program’ mode if you first ‘upgrade firmware’ on your UNO after you plug it in. (I think perhaps ‘upgrade’ firmware is a bit of a misnomer … I believe this just allows mBlock to load a piece of firmware onto the target Arduino which permits the real time communication between mBlock and the board). Anyway, it seems to be working as I think you have intended.

Your application is particularly interesting to me. I’m planning a volunteering activity at a local school (Southern CA for me) where I’d work with 4th - 6th grade students on some introductory Arduino programming. I’ve recently learned about Scratch (though it’s likely the kids have already had some exposure), and I’ve also come to the conclusion that mBlock looks like a good tool for running some Scratch/Arduino programs on Arduino boards.

I’d be interested in learning a bit more about your programming experiences with that age group (what works and what doesn’t) as well as some of the lessons you have been thinking about.


#10

As I mentioned, I have problems when I try to use “read analog pin A (0)” with green flag mode,
but I have no problems using “Digital Set pin (#) as output HIGH”. Anyway, I’ll keep trying.

On the other hand, I work with children 9-12 years with excellent results.
I wrote a curriculum based on some activities that already existed and others developed by me.
So far 90% of the activities are related to programming in Scratch and the rest with Arduino.

By the way, I’m from Mexicali, Baja California, which borders Southern California.


#11

Dear EduLibre,

I write this reply not for the topic of this discussion but interested in your edcuational activities. I also prepare some programing contents for 9~12 kids in Korea, and feel some trobles like slow mBlock process speed. Could you give me message through my mail? natruth76@gmail.com

Thanks in advance.


#12

Hello, I also work with students and Arduino. Have many tutorials. Trying to adapt mblock as well.
Also want to find out solution for reading data from analog pin. Have DHT 11 sensor and MQ 7 sensors that I would like to pull data from and display in mblock but cannot find out how to do this.