Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:27 19 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Setpin and pin()= problems

Author Message
Decoy
Senior Member

Joined: 02/08/2019
Location: Denmark
Posts: 109
Posted: 05:49pm 14 Aug 2019
Copy link to clipboard 
Print this post

Hi guys

I have just connected an LED to my UBW32 running MMBasic 4.5C

In editor I type:

setpin 30, DOUT
test:
pin(30)=1
pause 1000
pin(30)=0
pause 1000
goto test

Now, it seems that the setpin x, DOUT command sets the pin high right away?
Also, pin(30)=0 doesn't seem to set the pin low at all, if I just type and run:

setpin 30, DOUT
pin(30)=0

Any advice? I thought this would remind me more of Arduino-style logic?

Thanks!
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 06:12pm 14 Aug 2019
Copy link to clipboard 
Print this post

The pin numbers used by MMBasic are different to the UBW32 numbers.

0 - 20 are the 'standard pins, then D0 to D13 and A0 to A5 for the 'Arduino pins'

D0 to D13 have the aliases 21 to 34, so your pin(30) is Maximite pin Arduino D9.

Looking at the circuit diagram, this is the pin labelled A7 on the UBW32.

You should begin by trying pin 0 (in MMBasic) which will work the UBW32's on board yellow LED.
 
Decoy
Senior Member

Joined: 02/08/2019
Location: Denmark
Posts: 109
Posted: 06:43pm 14 Aug 2019
Copy link to clipboard 
Print this post

Hi

Yes, pin 30 is connected to A7 on the UBW32. Typing setpin 30, DOUT will turn on the pin and set it high right away. Typin pin(30)=0 will not turn it off.

pin(0)=1 and 0 works!
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 07:01pm 14 Aug 2019
Copy link to clipboard 
Print this post

How have you got your LED connected?  What resistor value?  Are you connecting the other pin of the LED to Gnd or 3.3V ?
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 07:08pm 14 Aug 2019
Copy link to clipboard 
Print this post

Have you tried:

pin(D9)= ...


instead ?
Andre ... such a GURU?
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 07:20pm 14 Aug 2019
Copy link to clipboard 
Print this post

It works on my UBW32 using pin(30) and the pin labelled A7.  I'm using a 1K resistor in line with the LED, other pin to GND.

I made a short Youtube video showing the circuit and program.  Not brilliant quality but maybe it will help.

https://youtu.be/HrcVuXq5jyw
 
Decoy
Senior Member

Joined: 02/08/2019
Location: Denmark
Posts: 109
Posted: 08:12pm 14 Aug 2019
Copy link to clipboard 
Print this post

Wow, I am amazed that you took the time to do a video!!
Thanks for that. I recently left social media, because (in part) I always loved forums I used to frequent back in the day. A response like that video, is a prime example of why old-school forums are awesome.

Now for the sad news. From a perspective of complete transparency - I must admit that I messed up big time. I reversed the leads of the LED  

I just re-did it, and it works perfectly.

Sorry for that!!
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 09:02pm 14 Aug 2019
Copy link to clipboard 
Print this post

The UBW32 pins (also Arduinos and similar) can source or sink current.  So when I wire up a LED to flash and it doesn't work, I just swap the other wire between Gnd and 3.3V.  

I normally try to look inside transparent LEDs from the side - they have a little cup connected to one leg and a wire apparently dangling into the cup on the other.  I mutter to myself the mantra "C for cup, C for cathode" while doing this!

If you've not already mutilated the LEDs legs, then the longer one is usually the one to connect to the positive side.

While we're in the spirit of admitting our errors, I was working on my MANIC MINER conversion a couple of days ago.  I had one file doing the intro theme, and a separate one playing the actual game.  After spending all day making code changes to the game program, I decided to add some chain commands to make each program load the other one. Somehow, and I'm still not sure how, I managed to overwrite the game program with a copy of the intro theme - so losing a whole day's work.  

I shall be very careful to take multiple backups before adding in any chain commands in future!
Edited 2019-08-15 07:03 by ceptimus
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 03:37pm 15 Aug 2019
Copy link to clipboard 
Print this post

  Poppy said  Have you tried:

pin(D9)= ...


instead ?


Still asking ...

... having no UBW32 IŽd like to know if its MMBASIC Version also supports the Arduino Pin-Names?


Andre ... such a GURU?
 
ceptimus
Senior Member

Joined: 05/07/2019
Location: United Kingdom
Posts: 130
Posted: 04:20pm 15 Aug 2019
Copy link to clipboard 
Print this post

It does - MMBasic doesn't know that it's running on a UBW32 - it's exactly the same chip as the one inside a "real" Maximite - and you load that chip with exactly the same version of MMBasic (currently V4.5C).

But the pins on the UBW32 are labelled with the PIC32 names instead of the Maximite names - so if your program used pin(D9) that pin would be labelled A7 on the UBW32.

It's not at all confusing, really! See http://geoffg.net/Images/Maximite/SchematicLarge.png
Edited 2019-08-16 02:27 by ceptimus
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 06:46pm 15 Aug 2019
Copy link to clipboard 
Print this post

Thanks!

Andre ... such a GURU?
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024