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


#13

You will need to wrap up the digitalWrite function so it can be called from scratch I show here the 1 that I made https://www.youtube.com/watch?v=IMF2uohqpdM&feature=youtu.be

You will also need to wrap up the binary shift left operator


#14

Thankyou, thats going to be really helpful. Im sure with this headstart I’ll get the hang of this!


#15

This is very interesting. I can see with a value of 128 I’d be expecting 1 0 0 0 0 0 0 0 in the count loop to shift…im getting only 7 output bits - so this gives me some hope. Thankyou, I’ll let you know how I go with this. PS. Would you mind sharing how you add your debug lines - I presume its either using the mblock console, or a serial monitor?

Cheers, and thanks again for the help!


#16

Hi, I simply copied the code from MBLOCK into the Arduino sketch application and ran the code from there using the serial monitor as you suggest - a fairly tedious operation because every time you modified MBLOCK code you’d have to repeat this exercise, but it’s the only way I could think of to visualise the outputs.

Snippets of code below

      for(int count=0;count<10;count++){
          Serial.print("count "); Serial.print(count); Serial.print(" |");
          tval = value;
          Serial.print("tval "); Serial.print(tval); Serial.println(" |");
          counter = 0;
          divi = 128;

          digitalWrite(latch,0);
          Serial.print("pin latch "); Serial.print(latch); Serial.print(" low |");  
          while(!(counter == 8.000000))
          {

etc!


#17

Hi, Thanks…hadn’t thought of that. I’d assume there might be a way to write to the serial monitor/console in mblock, in upload mode? Maybe Im getting ahead of myself! Again thankyou for shedding some light on what might be going on! Will update if I get anywhere with it…


#18

I have ordered a a HC-05 Bluetooth module that simulates a com port from your PC to the UART post on your Ardunio over Bluetooth. Once it arrives then I plan to connect to 2 one of the other UART posts on the Auriga board (meag2560) and open a serial terminal on my computer to receive debug info.


#19

Now that is the biz!. Many $ for that BT module?


#20

suspect you may not have had a debug line in the then as well as else on the if ! im getting 8 bits…however, convinced that outofthebots iss right its to do with data types, though i am writing 1 and 0 to the ports NOT variables. ?? still havent figured it out - will keep looking!


#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.