Arduino - emulating Shiftout (74HS595) - in mblock?


#21

Gents,

This started me thinking about looking at the code that was being produced, rather than the mblock! Turns out the problem was pretty annoyingly simple, …my mblock code generates the following;

float counter = 0;
float latchPin = 0;
float clockPin = 0;
float dataPin = 0;
float divi = 0;
float outputbit = 0;
float tval = 0;
float result = 0;
float wait = 0;
float digit = 0;
float value = 0;

void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
pinMode(latchPin,OUTPUT);
pinMode(dataPin,OUTPUT);
pinMode(12,OUTPUT);
pinMode(6,OUTPUT);
pinMode(13,OUTPUT);
pinMode(clockPin,OUTPUT);
wait = 0.001;
dataPin = 8;
clockPin = 10;
latchPin = 9;

Note the assignment of variables comes AFTER the pin setup! If I move the assignments BEFORE the pin setup - voila!!!.. this could be a problem with the code generation unless Im missing something really obvious…anyway I’m back on track, and my 7 yo is talking to me again :wink: Cheers for the help and encouragement…

float counter = 0;
float latchPin = 0;
float clockPin = 0;
float dataPin = 0;
float divi = 0;
float outputbit = 0;
float tval = 0;
float result = 0;
float wait = 0;
float digit = 0;
float value = 0;

void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
dataPin = 8;
clockPin = 10;
latchPin = 9;
pinMode(latchPin,OUTPUT);
pinMode(dataPin,OUTPUT);
pinMode(12,OUTPUT);
pinMode(6,OUTPUT);
pinMode(13,OUTPUT);
pinMode(clockPin,OUTPUT);
wait = 0.001;


#22

I have ordered this 1 https://www.aliexpress.com/item/32687878679.html?spm=a2g0s.9042311.0.0.510b4c4dSsLmU6 as it seems to be able to handle 5v on the RX pin as most modules will only handle 3.3v on the RX pin


#23

Thats a bargain for AUD$5 ! Will come in handy for the project I’m working on - must grab one. PS. Proved the point - forcing the ports to set OUTPUT using a literal number as opposed to a variable fixes it too! Darn frustrating!..ah well all good fun in these interesting times

Cheers


#24

Well done! Can’t believe I didn’t spot that. I guess sometimes you miss the small stuff when looking for something bigger! Glad you got to the bottom of it.


#25

OK I have found a work around for your problem. I create a second block for setting up the Pin_mode then all is good :slight_smile:


#26

Yeah, was a duh moment for sure. Im gonna have to let them know. Im no C guru but I reckon that’s just a sequencing issue in their code generation…Thanks again and take care with everything going on its a good time to lock yourself up with machinery!


#27

Thats a neat way to do it, but I still think their code generation shouldn’t set the ports to OUTPUT before the port is defined!..

Cheers

and good luck with your BT monitor idea, be interested in how you go with it!


#28

Hi,
If the same problem show as here, our engineer is working on to fix it.
Thanks.


#29

I would really appreciate any hints as to why the following code doesnt effectively mimic the shiftout snippet you provided above. Apologies I’m hanging onto this, as Id really like to teach my kids how to control the arduino using mblock - not C or tubemate at this stage! or mobdro as well


#30

Hi namanjohnson101,
May I know which board you have?
Please show me the code that you are using to test.
Thanks.


#31

Hi,

Thankyou, yes it is exactly that problem. I didn’t come across that post unfortunately, but am really pleased that its being worked on!

Enjoying mblock

Regards
Chris


#32

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.