Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Grawl
Aug 28, 2008

Do the D.A.N.C.E
1234, fight!
Stick to the B.E.A.T
Get ready to ignite
You were such a P.Y.T
Catching all the lights
Just easy as A.B.C
That's how we make it right
If I want to get started with this, and I get this from DX, is there anything else I need except hope, guidance and a strong will?

Adbot
ADBOT LOVES YOU

Hadlock
Nov 9, 2004

That should be fine. I would grab one of these OLED displays while you're at it, the Adafruit 1306ssd and U8G libraries both support it at about 60-90fps. You can do simple things or full graphics, the choice is yours.

http://www.dx.com/p/0-96-128x64-i2c-interface-white-color-oled-display-module-for-arduino-avr-arm-pic-346540

I always like to have a couple of these mini breadboards on hand, because sometimes you want to wire some new toy in to your existing setup without rewiring the whole thing, or figure out how to split the voltage before making room on your main breadboard.

http://www.dx.com/p/mini-prototype-printed-circuit-board-breadboard-for-arduino-5-pcs-148443

And of course extra jumper wires. Nothing slows you down more than finding your last long Blue/Green/Black wire to use for a ground, or your last yellow/red/orange short jumper wire to power something else

http://www.dx.com/p/breadboard-jumper-wires-for-electronic-diy-65-cable-pack-118826

Sir Bobert Fishbone
Jan 16, 2006

Beebort
Not strictly code-related, but does anyone have any experience with automating the turning of an existing quarter-turn ball valve with an Arduino? Without having seen the valve in question yet, I'm assuming I'd be looking at some sort of servo contraption to accomplish this, but I'm hoping someone might have done something similar already and can point me in the right direction.

Similarly, I'll need to automate the flipping of a standard toggle switch. Possible? Would I be able to use some sort of a push-pull solenoid, a linear actuator, or ???

Thanks!

Bad Munki
Nov 4, 2008

We're all mad here.


I'm sure it's possible, but those valves take a fair amount of torque. Is it at all possible to put a solenoid valve in instead, or in parallel? That would almost certainly be far simpler and much more reliable.

Sir Bobert Fishbone
Jan 16, 2006

Beebort

Bad Munki posted:

I'm sure it's possible, but those valves take a fair amount of torque. Is it at all possible to put a solenoid valve in instead, or in parallel? That would almost certainly be far simpler and much more reliable.

It's a good question, and given my druthers I'd definitely use something other than a manual ball valve, but I'm not optimistic that it's possible. I'm going to take a look at the existing setup in a couple hours, so we'll see what the situation is then.

The amount of torque this thing might need is definitely worrisome. Is there a reliable and fairly simple way to...measure the amount of torque a valve or lever needs to move? Or is that a massive moving target?

Bad Munki
Nov 4, 2008

We're all mad here.


Definitely going to depend on the valve.

Care to share details on the project? I'm guessing...grow op? In which case definitely try to use the solenoid valve, in parallel if you want a bypass, and for your grow lights, there are way better options than trying to manually control an actual light switch. You'll have the dankest nugs in no time.

Sir Bobert Fishbone
Jan 16, 2006

Beebort

Bad Munki posted:

Definitely going to depend on the valve.

Care to share details on the project? I'm guessing...grow op? In which case definitely try to use the solenoid valve, in parallel if you want a bypass, and for your grow lights, there are way better options than trying to manually control an actual light switch. You'll have the dankest nugs in no time.

Nah, it's part of a friend's relatively small commercial barley malting setup. I've done some Arduino work for him in the past--temperature controllers, SMS notifications, etc.--to try and automate some of the tasks, but this'd be my first foray into more of a physical engineery territory. I think he's looking to have this thing manipulate products that already exist and have already been installed, and I don't want to commit to do something if it's not really feasible or possible.

Bad Munki
Nov 4, 2008

We're all mad here.


Okay, well, if I were doing it and were dead set on using the existing ball valve...I don't think a servo would be the right answer. I think what I would do is drill a hole in the end of the handle, and connect that to a linear actuator of some sort, maybe a threaded rod with a motor-drive nut, or (probably better) a captive nut on the handle with some threaded rod attached to a motor. Spinning the motor will drive the nut up and down the rod, thus opening/closing the valve. Since it's a quarter-turn, you should be able to find a mounting angle for the rod/motor that will work, of course also allowing the rod/motor assembly to swivel a bit so it all lines up right. I can draw a picture if you need. Granted, this would make for a slower toggle of the valve, but would probably be the easiest way to get the torque you need.

As for the lightswitch, I would absolutely not try to jury rig something to manually control it and instead just wire something up in parallel. It's a lot less invasive to add a control circuit in parallel to the switch than it would be for the ball valve. A relay (solid state or otherwise, depending on your amperage/voltage needs) would do just fine.

Bad Munki fucked around with this message at 16:17 on May 1, 2015

Sir Bobert Fishbone
Jan 16, 2006

Beebort

Bad Munki posted:

Okay, well, if I were doing it and were dead set on using the existing ball valve...I don't think a servo would be the right answer. I think what I would do is drill a hole in the end of the handle, and connect that to a linear actuator of some sort, maybe a threaded rod with a motor-drive nut, or (probably better) a captive nut on the handle with some threaded rod attached to a motor. Spinning the motor will drive the nut up and down the rod, thus opening/closing the valve. Since it's a quarter-turn, you should be able to find a mounting angle for the rod/motor that will work, of course also allowing the rod/motor assembly to swivel a bit so it all lines up right. I can draw a picture if you need. Granted, this would make for a slower toggle of the valve, but would probably be the easiest way to get the torque you need.

As for the lightswitch, I would absolutely not try to jury rig something to manually control it and instead just wire something up in parallel. It's a lot less invasive to add a control circuit in parallel to the switch than it would be for the ball valve. A relay (solid state or otherwise, depending on your amperage/voltage needs) would do just fine.

Would you be able to draw a quick pic? I'm having a hard time imagining this setup working over a full 90 degrees of handle rotation. I kind of like it in principle, though.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
How about using a gearbox/stepper motor combo? Choose a gearbox that'd give you the right amount of torque and mount it on the valve stem, then drive the stepper motor off the Arduino via an appropriate motor driver board for whatever number of steps you determine to be sufficient to turn it 90 degrees. A proper solenoid valve would be my first go-to, but you know your setup better than I do.

For the lightswitch, the SSR in parallel with the existing switch that Bad Munki mentioned would be simple and reliable.

Bad Munki
Nov 4, 2008

We're all mad here.


Sir Bobert Fishbone posted:

Would you be able to draw a quick pic? I'm having a hard time imagining this setup working over a full 90 degrees of handle rotation. I kind of like it in principle, though.
The key is to mount it at a 45 with the axis of the actuator going roughly through the endpoints of the handle at open/close positions. I am a rather accomplished artist, so here you go:



The black is the pipe and the body of the valve, with the red handle currently shown in the closed position, dotted red is open, red arrow is the travel. The grey box in the upper right is your motor, the dotted grey corkscrew is, in this example, a leadscrew. The motor is able to swivel about the pink dot, and the pink lines show a rough approximation of how much it'll need to swivel to keep its axis in line with the captive nut on the end of the handle.

The further back you can mount your motor along that grey axis, the less swivel you'll need and the more consistent your torque will be. Mount it right up against the pipe and you'll have a very large amount of swivel and almost no torque at one end of the travel or another, but a fairly small installation. Mount it in the next room over and you'll have effectively no swivel and no change in torque, but you'll need a linkage 20 feet long.

Bad Munki fucked around with this message at 17:00 on May 1, 2015

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


You can also get a long stick across the valve handle and use a motor and some fishing line wrapped around the shaft. The longer your stick, the more leverage you have. A couple of limit switches are also needed, but their implementation is left as an exercise for the user.

Only registered members can see post attachments!

Bad Munki
Nov 4, 2008

We're all mad here.


That'll have little to no torque as it approaches the fully open position, at least in that arrangement. Move the motor off to the side so it's pulling at an angle in all positions.

Instead of limit switches, if you could sense current on the motor, you could just watch for stall, as that would both safeguard against burning out on a stuck valve, and also automatically shut off at either extent. Of course, that may lead to undesirable failure states, like maybe it should alert if it can't close all the way or something, and you'd need some way to differentiate between stalling on a stuck valve and stalling on a completed position change.

Bad Munki fucked around with this message at 18:11 on May 1, 2015

Sir Bobert Fishbone
Jan 16, 2006

Beebort
Thanks for all the help! Y'all are way smarter than I am when it comes to this kind of thing.

I just went and took a look at the setup. It looks like we'll be able to cut into the water supply and throw a solenoid valve in there after all, bypassing the ball valve entirely.

I'll probably still need a servo to manipulate a knob down the line, but at least that seems relatively simple to accomplish.

Bad Munki
Nov 4, 2008

We're all mad here.


For what it's worth, if you're able to modify the system, put the solenoid valve in parallel with the ball valve. It's always good to have a manual backup, and if the auto system doesn't work out as intended, going back to manual until it gets sorted out is a non-issue then. Just leave the valve closed when operating in automatic mode, and get a solenoid valve that is normally closed so it fails shut.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Bad Munki posted:

That'll have little to no torque as it approaches the fully open position, at least in that arrangement. Move the motor off to the side so it's pulling at an angle in all positions.

Instead of limit switches, if you could sense current on the motor, you could just watch for stall, as that would both safeguard against burning out on a stuck valve, and also automatically shut off at either extent. Of course, that may lead to undesirable failure states, like maybe it should alert if it can't close all the way or something, and you'd need some way to differentiate between stalling on a stuck valve and stalling on a completed position change.

The torque multiplication from this is really impressive. If you find you don't have enough torque, you can make the stick longer. Putting it at an angle so it goes from -45 to 45 works too.

As with anything, mock it up. If it doesn't work, you can figure out what's wrong and make changes.

Bad Munki
Nov 4, 2008

We're all mad here.


babyeatingpsychopath posted:

The torque multiplication from this is really impressive. If you find you don't have enough torque, you can make the stick longer. Putting it at an angle so it goes from -45 to 45 works too.

As with anything, mock it up. If it doesn't work, you can figure out what's wrong and make changes.

I don't mean torque at the optimal angle, I mean torque as you're trying to pull it the last couple degrees to shut. At that point, with the motor in that position, you're trying to pull it straight, instead of sideways.

Some sort of X-configuration on the belt would largely alleviate that, though.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Bad Munki posted:

I don't mean torque at the optimal angle, I mean torque as you're trying to pull it the last couple degrees to shut. At that point, with the motor in that position, you're trying to pull it straight, instead of sideways.

Some sort of X-configuration on the belt would largely alleviate that, though.

I understand what you meant. I'm saying that when I did this precise thing with stuff lying around, the depicted configuration worked. The valve handle didn't go all the way down to parallel to the pipe before the fishing line spun on the shaft, but the valve was closed, so good enough. I put the limit switch a degree or so before that point.

To rant a little bit:

I see a bunch of people trying to engineer the best possible solution to a problem instead of just finding stuff in their junk box and rigging something up to see if it works. I needed to turn a valve, so I got a random motor, some fishing line, a literal stick from the yard, and some tape. I lashed the motor to the pipe with the tape at what I thought might be an OK distance, taped the stick to the valve handle, and tied on the line. It worked. Not elegant, but I went from "have a problem" to "have a working solution" in about 7 minutes. If it hadn't worked, then I would have attempted to think about the problem and maybe come up with a more elegant solution. Pretty much everyone has a small motor of some kind. Trying to figure out what linear actuator to buy based on how much torque you need or figuring out which of dozens of servos to go with, trying to figure out how a mounting plate can work... you're a tinkerer and a hobbyist, not an engineer. If it's not life-critical or load bearing, then just slap something together and see where it fails and where it needs improvement. If nowhere, you're done and can move on to another project or spend your time engineering an elegant solution to replace your already-working project. Sure, in an actual industrial application you're going to have a rated-flow solenoid in parallel with a manual operator (or a manual operator on your solenoid), but that doesn't mean that's the only way to do things. Budget/hacky/rigged/ghetto/redneck solutions are only suboptimal for mass production.

Rant over.

Bad Munki
Nov 4, 2008

We're all mad here.


babyeatingpsychopath posted:

I understand what you meant. I'm saying that when I did this precise thing with stuff lying around, the depicted configuration worked. The valve handle didn't go all the way down to parallel to the pipe before the fishing line spun on the shaft, but the valve was closed, so good enough. I put the limit switch a degree or so before that point.
That's true, it'd almost certainly act as closed before it actually hit the hard stop.

quote:

To rant a little bit:
:bahgawd: tinker more :bahgawd:

It's a thread in an online forum, we're tinkering in our heads here, that's all.

Hadlock
Nov 9, 2004

Ebay has USB Type-C female port breakout boards now for about $5 shipped, if you wanted to start looking at integrating USB Type-C power (rated to 100w @ 5v, supposedly, dunno about this cheap Chinese ebay stuff though) in to your designs.

http://www.ebay.com/itm/DIY-24pin-U...=item3aa5cd9f85

edit: and male port breakout board as well. Be first to market with a pokemon shaped USB Type C USB flash drive

http://www.ebay.com/itm/DIY-24pin-U...=item3cf5cdc0b0

Hadlock fucked around with this message at 02:14 on May 10, 2015

Dylan16807
May 12, 2010

Hadlock posted:

Ebay has USB Type-C female port breakout boards now for about $5 shipped, if you wanted to start looking at integrating USB Type-C power (rated to 100w @ 5v, supposedly, dunno about this cheap Chinese ebay stuff though) in to your designs.

USB Power Delivery only gets you 100 watts if you're running at 20 volts; if ebay parts claim otherwise I would not trust them very far.

Oddly you're never supposed to feed more than 2 amps at 5v, even though the higher voltages can go to 5 amps.

Hadlock
Nov 9, 2004

Dylan16807 posted:

USB Power Delivery only gets you 100 watts if you're running at 20 volts; if ebay parts claim otherwise I would not trust them very far.

Oddly you're never supposed to feed more than 2 amps at 5v, even though the higher voltages can go to 5 amps.

Do you have a source for that 20v input? That's really interesting, I've seen a lot of USB-C stuff but nobody's been specific about the voltage before; I had always assumed it was just 5v, but it makes sense that it would do 20v, as most laptops will take 17-22v input. That's just a really wide range of inputs to accept over one port.

edit: ok yeah I see it now

website abc posted:

The initial specification for USB only had provisions for 0.75 watts of power – 150 mA at 5 V. USB 2.0 bumped that to 500 mA, or 2.5 watts, and USB 3.0 specified 900 mA at 5 V, or 4.5 watts. All of these specifications allow for power as well as data transmission at the same time. In addition, there was also a Battery Charging specification which allows up to 1.5 A at 5 V for a maximum of 7.5 watts of power but with no data transmission available. The jump from 7.5 watts to 100 watts of the new specification is a huge increase, and one that cannot be done with just an amperage increase on the system as was done in the previous versions of USB. Version 3.1 now supports 5 V, 12 V, and 20 V on the pins to allow the higher power output without excessive current, but even the current has been increased to a maximum of 5 A which is much higher than before.

http://www.anandtech.com/show/8539/usb-power-delivery-v20-and-billboard-device-class-v10-specifications-finalized

Hadlock fucked around with this message at 20:05 on May 10, 2015

poeticoddity
Jan 14, 2007
"How nice - to feel nothing and still get full credit for being alive." - Kurt Vonnegut Jr. - Slaughterhouse Five
Not sure if this should go in the Arduino Thread or the Embedded Systems Thread, but this is driving me insane.
I've got a 5V Trinket Pro (i.e. an Arduino with an alternate bootloader and no USB serial connection) I'm using as a slave device (over I2C) to an Arduino Uno in a project I'm working on for my dissertation. Without a direct serial-over-usb output, debugging has been painfully slow.
The Trinket Pro has 2 buttons and a rotary position encoder and will be handling subject input for my equipment. All it needs to do is send back whether each button has been pressed and what direction and how many increments/decrements the rotary encoder has been turned. The buttons are on (Arduino) Pins 0 & 1, and since the Trinket has no (Arduino) Pin 2, I've got it on (Arduino) Pins 3 & 4. I've got this ISR for Pin 3:
code:
attachInterrupt(1, pin3ISR, CHANGE);
code:
void pin3ISR() {
  REIntTime = millis();
  if (REIntTime > (lastREIntTime + rotaryDebounceTime)) {
   sendBytes[1] += ((PIND & B00010000) == B00000000) ? 1 : -1;
             lastREIntTime = REIntTime;
  }
}
For some reason I do not understand, the CCW (+= -1 condition) readings are basically perfect but the CW (+= 1 condition) are only accurate about 60% of the time and the rest of the time are either missed (no change) or read as CCW.
I don't think it's an issue with the debounce circuitry (I followed manufacturer recommendations for the encoder, and etched my own board and triple checked the connections) and my software debounce time is 50ms, which should be plenty. Tossing in a few 1-microsecond long blocks of NOPs before the line that reads PIND seems to have helped slightly, but the problem persists and I'm out of ideas.

JawnV6
Jul 4, 2004

So hot ...
What's consuming sendBytes? Could it be overwritten by another pass through the ISR before it gets sent?

Add a LED toggle to the end to check if it's firing at the rate you're expecting?

TheLastManStanding
Jan 14, 2008
Mash Buttons!
50ms for a debounce is really really slow. 5 milli would probably be long enough. If the encoder is using proper grey code, then you shouldn't even have to debounce.

change my name
Aug 27, 2007

Legends die but anime is forever.

RIP The Lost Otakus.

Hey everyone, I'm going to preference this with "I've never done anything with Arduino before": I volunteered to put together a presentation on connected design for my office in about 2-3 weeks, and I thought I should have something that actually works to go along with it.

What I want to do is build a zen garden where the rocks on top rotate in a circle once an IR sensor has been tripped. Kind of like a “passive motion tracker” since it would shut off when the person got up. I was thinking of having a stepper motor attached to a platter that spins once per hour (with magnets on top, and they drag the rocks around so that sand doesn't fall into the enclosure), and everything would be powered by a 5V 4400MaH usb battery pack and routed through the UNO I have already. I have this motor in my cart at the moment: http://www.adafruit.com/products/858, but someone in the office said it might be too weak. For reference, the garden would be in a 12"x12" box, and the platter would only be about 5" across?

Where should I start with this? Does it sound feasible?

poeticoddity
Jan 14, 2007
"How nice - to feel nothing and still get full credit for being alive." - Kurt Vonnegut Jr. - Slaughterhouse Five

JawnV6 posted:

What's consuming sendBytes? Could it be overwritten by another pass through the ISR before it gets sent?

Add a LED toggle to the end to check if it's firing at the rate you're expecting?

Sticking an LED toggle into the ISR helped with the debugging. Since the only time sendBytes[1] gets changed, other than during the ISR, is when it's reset to 0 on an I2C transmit request, but changing the ISR from "change" to "falling" seems to have done the trick, and that was much easier to test with the LED toggle. Thanks for the tip.


TheLastManStanding posted:

50ms for a debounce is really really slow. 5 milli would probably be long enough. If the encoder is using proper grey code, then you shouldn't even have to debounce.

I was trying to be a bit conservative with the software debounce. After changing the ISR trigger, I dropped it down to 10ms (I could probably go lower, but knowing whether or not that'd be helpful is going to take finishing the hardware) and it runs better. Thanks.

TheLastManStanding
Jan 14, 2008
Mash Buttons!
You should post the rest of your code. For an encoder the interrupt should be CHANGE, or else you'll miss half your steps. There also isn't any point to debouncing an encoder in software as far as I know. Having it momentarily wavering between two states is perfectly fine, where as debouncing can cause you to skip steps very easily.

ReelBigLizard
Feb 27, 2003

Fallen Rib

change my name posted:

Hey everyone, I'm going to preference this with "I've never done anything with Arduino before": I volunteered to put together a presentation on connected design for my office in about 2-3 weeks, and I thought I should have something that actually works to go along with it.

What I want to do is build a zen garden where the rocks on top rotate in a circle once an IR sensor has been tripped. Kind of like a “passive motion tracker” since it would shut off when the person got up. I was thinking of having a stepper motor attached to a platter that spins once per hour (with magnets on top, and they drag the rocks around so that sand doesn't fall into the enclosure), and everything would be powered by a 5V 4400MaH usb battery pack and routed through the UNO I have already. I have this motor in my cart at the moment: http://www.adafruit.com/products/858, but someone in the office said it might be too weak. For reference, the garden would be in a 12"x12" box, and the platter would only be about 5" across?

Where should I start with this? Does it sound feasible?

That motor is small but has decent torque, you may find it is a little slow. Project sounds feasible but I'm having trouble picturing what it looks like tbh.

change my name
Aug 27, 2007

Legends die but anime is forever.

RIP The Lost Otakus.

ReelBigLizard posted:

That motor is small but has decent torque, you may find it is a little slow. Project sounds feasible but I'm having trouble picturing what it looks like tbh.

1' x 1' box with the arduino, battery, breadboard etc on the bottom, connected to the motor. The motor has a thin disc attached to it, and the disc has magnets on the upper side. There's a sheet between the "zen garden" layer with sand and the bottom, pressed against the disc. As it spins, the magnets below pull along rocks with magnets on the bottom.

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

Making progress on my Arduino controlled LTC3780 DC-DC PSU.

Written my first Arduino OLED sketch... finishing off the hall effect sensor, then gonna order some digipots so I can control the volt/current of the buck/boost by the Arduino.



Amberskin
Dec 22, 2013

We come in peace! Legit!

Jamsta posted:

Making progress on my Arduino controlled LTC3780 DC-DC PSU.

Written my first Arduino OLED sketch... finishing off the hall effect sensor, then gonna order some digipots so I can control the volt/current of the buck/boost by the Arduino.


Is that one of those cheap chinese Arduino clones? How does it work? I've read some horror stories about the USB chip it uses and that is stopping me from getting some.

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

Amberskin posted:

Is that one of those cheap chinese Arduino clones? How does it work? I've read some horror stories about the USB chip it uses and that is stopping me from getting some.

Yup, it's a Nano clone - $2.68 all inc. from China.

They aren't bad at all. I've bought 6 so far, and they've all worked except one which I think I soldered badly. Small and cheap which is great for hobby work.

How do they work? Nearly identically to the larger Unos which again you can get for about $3 from China. You have to solder on the headers on, and there are less headers because of the smaller size.

I think the tolerances are lower on it (smaller regulators and caps), but I've been able to do everything I need with it.

Would recommend.

What's funny, was the OLED screen was about the same price. Looks amazingly clear, especially under direct sunlight/work lights.

DaveSauce
Feb 15, 2004

Oh, how awkward.
Question that's probably already been asked a dozen times but I can't seem to find it:

What's the best way to go about hooking an Arduino Uno up to a battery source?

I presume I don't want to just toss 4 AA batteries at it. I would guess I will want a voltage regulator and a reverse-polarity protection diode at a minimum. I have various bits sitting around, including a few rat shack 5V regulators and many 1N400X diodes. Are there any special considerations I need to know about to keep from frying the board, or is giving it voltage good enough?

Second question, slightly different subject:

How does one size a diode for surge protection on an inductive load like a motor or solenoid? And I mean actually size a diode, not just throw something at it and call it good.

I've always been taught to use a 1N4007 diode for 24VDC relay or solenoid coils (when the load doesn't already include one). Is this overkill? The 1N4007 is rated for 1000V reverse voltage. Not that cost is an issue, but I figure I should know how to size it correctly just in case I run across a situation where 1000V isn't enough, or in case I need to down-size to a properly engineered diode for some reason or another (package size/cost/etc.).

DaveSauce fucked around with this message at 13:12 on May 26, 2015

Collateral Damage
Jun 13, 2009

DaveSauce posted:

What's the best way to go about hooking an Arduino Uno up to a battery source?

I presume I don't want to just toss 4 AA batteries at it. I would guess I will want a voltage regulator and a reverse-polarity protection diode at a minimum. I have various bits sitting around, including a few rat shack 5V regulators and many 1N400X diodes. Are there any special considerations I need to know about to keep from frying the board, or is giving it voltage good enough?
The Arduino Uno board has a built in voltage regulator and you can feed it anything from 7 to 12V. I'm going to assume it's polarity protected too. I normally run mine off a 9V battery.

DaveSauce
Feb 15, 2004

Oh, how awkward.

Collateral Damage posted:

The Arduino Uno board has a built in voltage regulator and you can feed it anything from 7 to 12V. I'm going to assume it's polarity protected too. I normally run mine off a 9V battery.

That's good to know, thanks.

Does the board have any low-battery/low-voltage protection of any sort? Or will it just start to act screwy when battery voltage drops below a critical point?

Collateral Damage
Jun 13, 2009

I don't think it has any low voltage shut-off. The Arduino Uno page says:

quote:

The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

DaveSauce posted:

That's good to know, thanks.

Does the board have any low-battery/low-voltage protection of any sort? Or will it just start to act screwy when battery voltage drops below a critical point?

You could roll your own, or use a full on buck/boost with low voltage disconnect, like this

DaveSauce
Feb 15, 2004

Oh, how awkward.

Collateral Damage posted:

I don't think it has any low voltage shut-off. The Arduino Uno page says:

I saw that too...I was hoping it had something in there, but looks like that isn't the case. Instability without warning isn't cool.


Jamsta posted:

You could roll your own, or use a full on buck/boost with low voltage disconnect, like this

Yeah, I was going to try to piece something together. My thought was to use a zener or something to enable a relay or optoisolator that controls power to the board. Basically, only power the board if the supply voltage is high enough to avoid instability. Then if I feel like getting fancy, I want to figure out how to toggle a "Low Battery" light so I have some warning at least.

I'm sure I can find a chip or something that'll do it, but it'll be a fun exercise to help get my brain back in to electronics.

Adbot
ADBOT LOVES YOU

poeticoddity
Jan 14, 2007
"How nice - to feel nothing and still get full credit for being alive." - Kurt Vonnegut Jr. - Slaughterhouse Five

TheLastManStanding posted:

You should post the rest of your code. For an encoder the interrupt should be CHANGE, or else you'll miss half your steps. There also isn't any point to debouncing an encoder in software as far as I know. Having it momentarily wavering between two states is perfectly fine, where as debouncing can cause you to skip steps very easily.

code:
#include <Wire.h>
#include <avr/wdt.h>

//volatile byte rotaryVal = 0;
volatile unsigned long REIntTime = 0;
volatile unsigned long lastREIntTime = 0;
#define rotaryDebounceTime 10 //milliseconds
#define buttonCheckRefreshTime 100 //milliseconds
//WDTO *MUST* be longer than buttonCheckRefreshTime
#define watchDogDuration WDTO_500MS
//https://tushev.org/articles/arduino/5/arduino-and-watchdog-timer
unsigned long lastButtonTime = 0;

//Pin 0 - PD0 - top button
//Pin 1 - PD1 - bottom button
//Pin 3 - PD3 - RPE (int1)
//Pin 4 - PD4 - RPE

volatile byte buttonByte = 0; //Constructed to give info to master
byte sendBytes[] = {0, 0};
/*MSB & MSB+1: (PIND & B00000011)*/

volatile byte lastRotaryVal = 0;

unsigned long lastTime = 0;

void setup() {
  attachInterrupt(1, pin3ISR, FALLING);
  DDRB |= B00100000;
  Wire.begin(10);
  Wire.onRequest(requestEvent);
  wdt_enable(watchDogDuration);
}

void loop() {
  while((millis() - lastTime) < buttonCheckRefreshTime){
    buttonByte |= ((~PIND) & B00000011);
  }
  lastTime = millis();
  PORTB ^= B00100000;
  wdt_enable(watchDogDuration);

}

void requestEvent() {
  sendBytes[0] = buttonByte;
  Wire.write(sendBytes, 2);
  //sendBytes[0] = 0;
  sendBytes[1] = 0;
  buttonByte = 0;
}


void pin3ISR() {
  REIntTime = millis();
  if (REIntTime > (lastREIntTime + rotaryDebounceTime)) {
    sendBytes[1] += ((PIND & B00010000) == B00000000) ? 1 : -1;
    lastREIntTime = REIntTime;
  }
}
Changing "FALLING" to "CHANGE" causes the counterclockwise values to be larger (i.e. greater decrements), but the clockwise values to generally results in a series of conflicting increments and decrements. I have no idea why.

I had to put the watchdog timer in because button presses randomly (i.e. usually somewhere between the second and twelfth press) cause the main loop to crash (but usually not the requestEvent() or pin3ISR() routines, oddly. My guess for the source of this would be that the Trinket Pro I'm using (instead of a full Arduino) is designed to operate off of a battery and the debounce capacitors for the buttons allow more current through than the ones for the rotary encoder and it's browning out or something like that.

I've got it working well enough to do what I need reasonably well, but if anyone has suggestions for improvement, I'm all ears.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply