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
Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
Stupid question -- I am using a LED on the same pin (in parallel) as the optocoupler to make sure my code is behaving right before I start soldering and when the optocoupler is attached the LED will not light. When the optocoupler is not connected to ground the LED blinks as expected. Is that just a sign that the pin can't put out enough power to do both at once? There's currently a 200 ohm resistor to keep current down in front of both the LED and optocoupler, but I tried a ~50 ohm resistor and saw no change. So it's IO pin -> resistor -> and then it branches into LED and optocoupler in parallel.

It's no big deal as I wasn't intending to have the LED on the final but I'm kinda curious.

Adbot
ADBOT LOVES YOU

Aurium
Oct 10, 2010

Parts Kit posted:

Stupid question -- I am using a LED on the same pin (in parallel) as the optocoupler to make sure my code is behaving right before I start soldering and when the optocoupler is attached the LED will not light. When the optocoupler is not connected to ground the LED blinks as expected. Is that just a sign that the pin can't put out enough power to do both at once? There's currently a 200 ohm resistor to keep current down in front of both the LED and optocoupler, but I tried a ~50 ohm resistor and saw no change. So it's IO pin -> resistor -> and then it branches into LED and optocoupler in parallel.

It's no big deal as I wasn't intending to have the LED on the final but I'm kinda curious.

The optocoupler will have a much lower voltage drop than your led, and thus will take almost all of the current. You can get a similar effect if you parallel a blue and red led. Only the red led will light.

If you parallel a resistor and led pair with the resistor optocoupler it should work. Or if you series them all(unless the total voltage drop is too much.)

Dylan16807
May 12, 2010

Parts Kit posted:

Stupid question -- I am using a LED on the same pin (in parallel) as the optocoupler to make sure my code is behaving right before I start soldering and when the optocoupler is attached the LED will not light. When the optocoupler is not connected to ground the LED blinks as expected. Is that just a sign that the pin can't put out enough power to do both at once? There's currently a 200 ohm resistor to keep current down in front of both the LED and optocoupler, but I tried a ~50 ohm resistor and saw no change. So it's IO pin -> resistor -> and then it branches into LED and optocoupler in parallel.

It's no big deal as I wasn't intending to have the LED on the final but I'm kinda curious.

So you put two LEDs in parallel, more or less. LEDs have a minimum voltage and almost no resistance, so once you reach a high enough voltage to turn on one LED, it sucks down all the current and doesn't let the other get any. You need a resistor for each if you want them to share.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
Ah okay. That's pretty neat to know. Now I've got a working indicator. :buddy:

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

Has anyone had experience with the Maple? Anything I should be aware of bugs/usability wise?

I've ordered two of these for tinkering with:

http://www.ebay.co.uk/itm/New-STM32-ARM-Cortex-M3-Leaflabs-Leaf-Maple-Mini-Module-for-Arduino-/281591492549?hash=item4190292fc5

Dominoes
Sep 20, 2007

Hey dude. Not arduino, but general electronics question. What would cause PWM not to work with a DC motor? I have two DC motors: A water pump, and fan. I have two speed regulators: A voltage regulator, and a PWM device. The voltage regulator works well with both the fan and pump. The PWM works well with the fan. The pump shuts down when the PWM is throttled below 100%. What could cause this?

SybilVimes
Oct 29, 2011

Dominoes posted:

Hey dude. Not arduino, but general electronics question. What would cause PWM not to work with a DC motor? I have two DC motors: A water pump, and fan. I have two speed regulators: A voltage regulator, and a PWM device. The voltage regulator works well with both the fan and pump. The PWM works well with the fan. The pump shuts down when the PWM is throttled below 100%. What could cause this?

Obvious answer: it's not really a "DC motor" but probably something like BLDC.

Dominoes
Sep 20, 2007

It is indeed brushless; thanks.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
What's a good, small battery for use with a 5v Trinket? 4 AAAs should do it, but that's too much space and weight. I was thinking maybe 2 CR123As? That'll give me 6v, and while it's an uncommon battery I have plenty on hand from other hobby stuff.

sharkytm
Oct 9, 2003

Ba

By

Sharkytm doot doo do doot do doo


Fallen Rib

Dominoes posted:

It is indeed brushless; thanks.

So you could use an ESC driven with a PWM signal, maybe.

Collateral Damage
Jun 13, 2009

Parts Kit posted:

What's a good, small battery for use with a 5v Trinket? 4 AAAs should do it, but that's too much space and weight. I was thinking maybe 2 CR123As? That'll give me 6v, and while it's an uncommon battery I have plenty on hand from other hobby stuff.
A 3.7V Li-Ion pack and a DC booster? Adafruit has a couple of different tiny ones with or without built in Li-Ion charging circuitry.

edit: Booster only or booster with charge.

Collateral Damage fucked around with this message at 16:46 on Aug 13, 2015

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

Parts Kit posted:

What's a good, small battery for use with a 5v Trinket? 4 AAAs should do it, but that's too much space and weight. I was thinking maybe 2 CR123As? That'll give me 6v, and while it's an uncommon battery I have plenty on hand from other hobby stuff.

You can actually run a 5V Trinket off a 3.7V lipoly pack without any issues. The GPIO won't be at 5V (they'll be at battery voltage) but most things don't really need 5V anyways. It's worth a quick shot to see if it works for you since it would save having to add a little boost converter.

Aurium
Oct 10, 2010

mod sassinator posted:

You can actually run a 5V Trinket off a 3.7V lipoly pack without any issues. The GPIO won't be at 5V (they'll be at battery voltage) but most things don't really need 5V anyways. It's worth a quick shot to see if it works for you since it would save having to add a little boost converter.

3.7v is just outside margin for running an attiny at 16mhz.

Of course lots of people run various atmegas at the even lower 3.3v @16mhz with no problems, but it is out of spec. I wouldn't really worry about it, but if you get strange intermittent errors, find the instructions to drop it to 8mhz and see if it helps. According to adafruit, the 5v trinket even has a setting that makes it easy.

socketwrencher
Apr 10, 2012

Be still and know.
Just wondering if the following is possible, hopefully at a relatively low ($200 or so budget) expense- thanks for any feedback:

I'd like to link 3 LED or LCD screens (maybe 12"?) together and flash symbols on them. The screens will be viewed from 15-20 feet away and the symbols would be very large, basic, easy to read arrows. Think something like the Walk/Don't Walk prompts at intersections in terms of their visibility/legibility.

One symbol would flash on one screen at a time. It would be great if the flashes could be randomized, so if there are say 4 arrow symbols (up, down, left, right) they would flash randomly with the only provision being that there would be no consecutive flashes on the same screen.

Thanks for any help!

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass
Check out pygame for writing some software to display simple text and graphics: http://www.pygame.org/news.html It's a nice little python library for writing games and has a lot of functions for clearing the screen, drawing text using truetype fonts, etc.

For controlling 3 screens though it will be tricky to do it from one Pi. If the screens are completely independent of each other then a pi on each running a program would work. If they need to be synchronized or only display certain graphics when the other isn't, etc. then it gets a bit trickier. I think in that case a 4th pi or computer that controls the 3 pi's by sending them commands (even just something simple like SSH'ing in to the pi and running a shell script) would be the easiest approach.

edit: Durr got confused and thought I was in the Pi thread. :) For an Arduino driving a 12" LCD display will be tricky. You'll definitely need a display with an integrated driver since the Arduino doesn't have enough memory to store all the graphics of such a large display. Most 12" and larger displays are probably made to take HDMI or similar video input anyways so Arduino wouldn't work.

An LED display like these matrices would work though: https://www.adafruit.com/products/555 Just be careful since when you get too many displays and pixels you might run out of memory on the Arduino to handle drawing graphics on them. Worst case jump up to an Arduino Mega to get a more capable board.

And for any display you setup be careful to make sure you give it enough power. If you use an RGB LED matrix (like neopixels) get a really beefy power supply since they pull a lot of current.

mod sassinator fucked around with this message at 18:52 on Aug 14, 2015

socketwrencher
Apr 10, 2012

Be still and know.

mod sassinator posted:

Check out pygame for writing some software to display simple text and graphics: http://www.pygame.org/news.html It's a nice little python library for writing games and has a lot of functions for clearing the screen, drawing text using truetype fonts, etc.

For controlling 3 screens though it will be tricky to do it from one Pi. If the screens are completely independent of each other then a pi on each running a program would work. If they need to be synchronized or only display certain graphics when the other isn't, etc. then it gets a bit trickier. I think in that case a 4th pi or computer that controls the 3 pi's by sending them commands (even just something simple like SSH'ing in to the pi and running a shell script) would be the easiest approach.

Thanks for the link and info, I'm going to read it now as well as the other link provided.

Edit: The adafruit LED panel looks perfect. I really appreciate this because I'm flying blind.

socketwrencher fucked around with this message at 18:57 on Aug 14, 2015

Edward IV
Jan 15, 2006

I'm not sure if this is the right place to ask but I'm looking into using an Arduino to make an instant film printer and I need some component suggestions. Basically I'm making a Fujifilm SP-1 but hopefully faster (printing time for the SP-1 takes about 16 seconds because it prints line by line) and better suited for cameras and computers rather than smartphones and tablets (the SP-1 only works with an iOS or Android app or with select Fujifilm cameras). My idea is to use a Wifi SD card in my camera that send photos to the printer and a small, high pixel density screen, like the one on the iPhone 4 or Nokia N900, to expose the film. Other features that I would like to include is a second, external screen that will let me preview what image to print and being able to print with a PC. Would an Arduino be able to do this on it's own or will I also need micro-computer like a Raspberry Pi?

One key feature is being able to interface with a Wifi SD card which puts the Eye-Fi out of contention. There is the Toshiba FlashAir which can be sent commands through HTTP as described here: https://www.flashair-developers.com/en/

Will an Arduino be able to work with the FlashAir or will I need a Pi?

The second key feature is the screen that will expose the film which needs a relatively high pixel density to make the most use out of the film. The SP-1 is rated at 254 dpi and the printing area is 62mm x 46mm (3" diagonal, "resolution" of 640x480). Ideally, I want a screen that's slightly larger than the printing area and have the same or higher pixel density. However, finding one that's ready to use has been a challenge. Screens for Arduinos and the Pi have too low of a density or are too large to use. There are no available controller boards currently available to drive an iPhone 4 or N900 screen or documentation to do so. Actually, there is a controller board for the iPhone 4 that will have a HDMI input but there is no availability date given yet and I'd like to consider my options. Also for backlit LCD screen, I would like to be able to control the backlight and what shows up on the screen independently so that the pixels are in place with the image I want to print before the backlight turns on and exposes the film to prevent any unwanted artifacts from showing up on the film.

Any thoughts or suggestions on where I can go with this?

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

Edward IV posted:

I'm not sure if this is the right place to ask but I'm looking into using an Arduino to make an instant film printer and I need some component suggestions. Basically I'm making a Fujifilm SP-1 but hopefully faster (printing time for the SP-1 takes about 16 seconds because it prints line by line) and better suited for cameras and computers rather than smartphones and tablets (the SP-1 only works with an iOS or Android app or with select Fujifilm cameras). My idea is to use a Wifi SD card in my camera that send photos to the printer and a small, high pixel density screen, like the one on the iPhone 4 or Nokia N900, to expose the film. Other features that I would like to include is a second, external screen that will let me preview what image to print and being able to print with a PC. Would an Arduino be able to do this on it's own or will I also need micro-computer like a Raspberry Pi?

One key feature is being able to interface with a Wifi SD card which puts the Eye-Fi out of contention. There is the Toshiba FlashAir which can be sent commands through HTTP as described here: https://www.flashair-developers.com/en/

Will an Arduino be able to work with the FlashAir or will I need a Pi?

The second key feature is the screen that will expose the film which needs a relatively high pixel density to make the most use out of the film. The SP-1 is rated at 254 dpi and the printing area is 62mm x 46mm (3" diagonal, "resolution" of 640x480). Ideally, I want a screen that's slightly larger than the printing area and have the same or higher pixel density. However, finding one that's ready to use has been a challenge. Screens for Arduinos and the Pi have too low of a density or are too large to use. There are no available controller boards currently available to drive an iPhone 4 or N900 screen or documentation to do so. Actually, there is a controller board for the iPhone 4 that will have a HDMI input but there is no availability date given yet and I'd like to consider my options. Also for backlit LCD screen, I would like to be able to control the backlight and what shows up on the screen independently so that the pixels are in place with the image I want to print before the backlight turns on and exposes the film to prevent any unwanted artifacts from showing up on the film.

Any thoughts or suggestions on where I can go with this?

Honestly I would skip building a screen to do this and instead make a frame to hold a smartphone in a lightproof enclosure and expose the film. You're going to have a really tough time finding a 3" screen or so with that pixel density. You likely would have to buy some raw LCD panel, a board to drive it, etc. and I have a feeling it's going to be very expensive (like $100+).

An Arduino isn't really going to be up to the task of rendering a big digital camera image too (remember a basic Arduino Uno only has 2 kilobytes of memory, that's not enough to store even a tiny fraction of a normal 1-2 megabyte photo) so I'd stay away from using it here. You'd want at least a fast little ARM CPU with a lot of memory, or more likely a Raspberry Pi / small Linux computer. You'll have a much easier time hacking something together with a Raspberry Pi & Linux since you could use python libraries etc. to read from wifi SD card (I know there's a python library to receive eyefi pics, not sure about that other card).

But all that said I'd approach it a different way and focus on making a nice little phone app that takes a pic with the phone camera (or can even receive pics via wifi, most cameras sold today have wifi support), and then slides into a little box to expose the film. Even a modest $200 Android phone (like the Moto G) has a nice 300+ PPI display. Making a standalone piece of hardware to do this kinda complicates things.

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

Just got my Maple Mini STM32F103 boards, pain getting them into sketch flash mode...

Captain Cool
Oct 23, 2004

This is a song about messin' with people who've been messin' with you

Edward IV posted:

I'm not sure if this is the right place to ask but I'm looking into using an Arduino to make an instant film printer and I need some component suggestions. Basically I'm making a Fujifilm SP-1 but hopefully faster (printing time for the SP-1 takes about 16 seconds because it prints line by line) and better suited for cameras and computers rather than smartphones and tablets (the SP-1 only works with an iOS or Android app or with select Fujifilm cameras). My idea is to use a Wifi SD card in my camera that send photos to the printer and a small, high pixel density screen, like the one on the iPhone 4 or Nokia N900, to expose the film.
Looks like the SP-1 is a printer that takes digital photos as input. How and why are you exposing film in this process?

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass
It prints on Instax film, like what little Polaroid style Instax cameras use. Apparently it's just a LCD that displays a picture to the raw film and gets developed on it. There's no actual printing like an ink jet, etc.

poeticoddity
Jan 14, 2007
"How nice - to feel nothing and still get full credit for being alive." - Kurt Vonnegut Jr. - Slaughterhouse Five
Does anyone have any recommendations for a chip for multipliexing I2C signals? I'm looking to use multiple instances of the same sensor, but the address isn't reconfigurable. I'd prefer something in an SMD package that can handle 4 or more data lines each with moderate speed. I understand how a multiplexer works in abstract, but I'm getting hung up on the notation in the parametric search on digikey.

SybilVimes
Oct 29, 2011

poeticoddity posted:

Does anyone have any recommendations for a chip for multipliexing I2C signals? I'm looking to use multiple instances of the same sensor, but the address isn't reconfigurable. I'd prefer something in an SMD package that can handle 4 or more data lines each with moderate speed. I understand how a multiplexer works in abstract, but I'm getting hung up on the notation in the parametric search on digikey.

Should be able to use a simple 74*244 and 74*138 pair to switch the SCL line to each slave device. that should give you 8 easily controlled signals. Don't try to multiplex the data (SCA) line.

Aurium
Oct 10, 2010

poeticoddity posted:

Does anyone have any recommendations for a chip for multipliexing I2C signals? I'm looking to use multiple instances of the same sensor, but the address isn't reconfigurable. I'd prefer something in an SMD package that can handle 4 or more data lines each with moderate speed. I understand how a multiplexer works in abstract, but I'm getting hung up on the notation in the parametric search on digikey.

Hackaday recommended the PCA9547 about a month ago.

Disclaimer, never personally used it.

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

neogeo0823
Jul 4, 2007

NO THAT'S NOT ME!!

I'm in the early stages of a project and I'm looking for some advice. I have a water pump that pumps into a pressure chamber(essentially a balloon), and when it gets full enough, the chamber pushes two contacts together and closes them, which powers a relay that stops the pump. A button controls a solenoid that lets the water flow out of the chamber. The button, contacts, and relay are all routed through/controlled by the Arduino. What I want to do is have the Arduino check for leaks in the system. Basically, if the pump starts running when the button hasn't first been pressed, it shuts off the pump. However, the pump takes a longer time to fill the chamber than the button would have been held down for, so I don't want to have the pump be shut off just because the button isn't currently being held down.

Does that make sense? If so, could someone please help me out with sketching that out? Thanks.

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!
I just got an Arduino and an Adafruit motor shield, and I'm a bit confused as to how to actually make the motors... move. I've got the AF motor library and all that, but the example sketches I've loaded just don't seem to work. Do I have to declare a motor shield object, or not? Some of the code I see floating around on the Net seems to suggest yes, others no.

Hadlock
Nov 9, 2004

Huh not sure what your issue is, but here is my adafruit motor shield, and here is my sketch that I uploaded to it. I think depending on the Arduino used, the I2C pins can be Analog 2,3 instead of 0,1. If you have the smaller Leonardo chip that is the case, I think. It's been a while since I hosed with it.

http://pastebin.com/mkA0pWn9

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

neogeo0823 posted:

I'm in the early stages of a project and I'm looking for some advice. I have a water pump that pumps into a pressure chamber(essentially a balloon), and when it gets full enough, the chamber pushes two contacts together and closes them, which powers a relay that stops the pump. A button controls a solenoid that lets the water flow out of the chamber. The button, contacts, and relay are all routed through/controlled by the Arduino. What I want to do is have the Arduino check for leaks in the system. Basically, if the pump starts running when the button hasn't first been pressed, it shuts off the pump. However, the pump takes a longer time to fill the chamber than the button would have been held down for, so I don't want to have the pump be shut off just because the button isn't currently being held down.

Does that make sense? If so, could someone please help me out with sketching that out? Thanks.

What you might do is use the millis() function to get the current 'time' (really just a millisecond counter value) when the button is pressed and then add however long it normally takes to fill the pressure chamber and consider that a 'time-out' value that if the pump is running after it then something is wrong and the pump should stop. You do have to be careful when using a counter like this as it's really easy to overflow the numeric value and get your math wrong so bugs are introduced. The millis() counter is a 32 bit unsigned value so it will overflow and loop back to zero after 2^32-1 milliseconds, or about 49 days. This can introduce very subtle bugs where everything is great for a month and then things mysteriously stop working.

The right way to handle this is to expect and deal with the overflow of millis. First use a 32-bit unsigned value to store the millis() value to make sure you don't accidentally lose precision with a smaller type. Then add to that your max runtime in milliseconds to get the pump stop time, i.e. the point where after that time the pump should never be running until the button is pressed again. Finally check if your pump stop time is less than the start time--this means the counter will overflow during the period and your logic to check if outside the pump stop time needs to be a little different. Here's some pseudocode of what I mean using 5 seconds as a pump stop time:
code:
// Button is pressed!  We need to make sure the pump stops running after 5 seconds and doesn't run again until the button is pressed.
// Get the current 'time' the button was pressed using millis().  Make sure to store it in a 32-bit unsigned type.
uint32_t buttonPress = millis();

// Now add 5 seconds to the button press time to know when the pump should never be running.
uint32_t pumpStop = buttonPress + 5000;  // Remember it's milliseconds, 1000ms = 1 second.

// Be cafeful, pumpStop might be LESS than buttonPress!  This happens when the millis() counter is
// within 5 seconds of overflowing.  We'll deal with this later in the loop below.

// Main loop to start the pump and check if the contacts are pressed to stop it.
while (true) {
  // Check if the contacts are pressed that tell you the pressure chamber is full.
  // When filled stop the pump and break out of the loop.  Consider yourself in a pump stopped state until the button is pressed again.

  // Check if we've exceeded the time-out/pump stop time.
  // First grab the current 'time'.
  uint32_t now = millis();
  // Now check if we expect millis() to overflow during the normal pump running time, i.e. pumpStop is less than buttonPress.
  if (pumpStop < buttonPress) {
    // Expect millis() to overflow, so check if the currentTime is greater than the stopTime and less than the startTime to know when to stop.
    if (now >= stopTime && now < startTime) {
      // We hit the pump stop time!  Force the pump to stop and break out of the loop.  Consider yourself in a pump stopped state until the button is pressed again.
    }
  }
  else {
    // Else millis() will not overflow during the normal pump running time, so just check if it's greater than the stop time.
    if (now >= stopTime) {
      // We hit the pump stop time!  Force the pump to stop and break out of the loop.  Consider yourself in a pump stopped state until the button is pressed again.
    }
  }
}
In general you'll want to be really careful about overflow and try to setup test scenarios to make sure everything works. Setup your hardware just with switches and buttons to simulate the pumps, relays, etc. and control them yourself during the testing.

Also if this is a safety critical system, i.e. where people can be hurt or their lives depend on the pressure chamber, pump, etc. working and not exploding, then absolutely put everything down and get a real engineer to help you. An Arduino is really not suited for safety critical systems. Its firmware is for education use and fun, it has not been rigorously tested and definitely has bugs, etc. You might upgrade to a new Arduino version and the millis() function behaves completely differently and breaks your system in unexpected ways.

neogeo0823
Jul 4, 2007

NO THAT'S NOT ME!!

mod sassinator posted:

What you might do is use the millis() function to get the current 'time' (really just a millisecond counter value) when the button is pressed and then add however long it normally takes to fill the pressure chamber and consider that a 'time-out' value that if the pump is running after it then something is wrong and the pump should stop. You do have to be careful when using a counter like this as it's really easy to overflow the numeric value and get your math wrong so bugs are introduced. The millis() counter is a 32 bit unsigned value so it will overflow and loop back to zero after 2^32-1 milliseconds, or about 49 days. This can introduce very subtle bugs where everything is great for a month and then things mysteriously stop working.

The right way to handle this is to expect and deal with the overflow of millis. First use a 32-bit unsigned value to store the millis() value to make sure you don't accidentally lose precision with a smaller type. Then add to that your max runtime in milliseconds to get the pump stop time, i.e. the point where after that time the pump should never be running until the button is pressed again. Finally check if your pump stop time is less than the start time--this means the counter will overflow during the period and your logic to check if outside the pump stop time needs to be a little different. Here's some pseudocode of what I mean using 5 seconds as a pump stop time:

code:
(code)
In general you'll want to be really careful about overflow and try to setup test scenarios to make sure everything works. Setup your hardware just with switches and buttons to simulate the pumps, relays, etc. and control them yourself during the testing.

Also if this is a safety critical system, i.e. where people can be hurt or their lives depend on the pressure chamber, pump, etc. working and not exploding, then absolutely put everything down and get a real engineer to help you. An Arduino is really not suited for safety critical systems. Its firmware is for education use and fun, it has not been rigorously tested and definitely has bugs, etc. You might upgrade to a new Arduino version and the millis() function behaves completely differently and breaks your system in unexpected ways.

Thanks, this is really helpful. While this isn't safety critical in the sense of people getting hurt or anything, the water system is going to be near enough to the Arduino and other circuitry where a leak may cause shorts and water damage. Being able to automatically shut off the pump in that event can turn a leak from a 2-3ft spray down to a trickle, which would potentially save a lot of wiring and work.

Just to clarify a few things, the system won't always be on and powered, and certainly not for more than a day or two at maximum, so keeping track of timing bugs after a month shouldn't be an issue, correct? Also, I'm not sure how much, if any, this would change the solution, but the time the button will be held down to release water can and will vary. I'd expect it to vary between maybe half a second and upwards of around 10 seconds. So just to make sure I'm understanding it correctly, the first two lines of code times how long the button was pressed for, and then adds 5 seconds to that time to determine when the pump should never be running, correct? Since we're dealing with times less than ~15 seconds total, we won't have to worry about the PumpStop value overflowing, right? If so, I'd still keep the overflow protection in there, just for redundancy.

DrSunshine
Mar 23, 2009

Did I just say that out loud~~?!!!

Hadlock posted:

Huh not sure what your issue is, but here is my adafruit motor shield, and here is my sketch that I uploaded to it. I think depending on the Arduino used, the I2C pins can be Analog 2,3 instead of 0,1. If you have the smaller Leonardo chip that is the case, I think. It's been a while since I hosed with it.

http://pastebin.com/mkA0pWn9



Tried this and it works out fine! Whew! I'm at least glad that all my parts work fine. Thanks!! :D

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

neogeo0823 posted:

Thanks, this is really helpful. While this isn't safety critical in the sense of people getting hurt or anything, the water system is going to be near enough to the Arduino and other circuitry where a leak may cause shorts and water damage. Being able to automatically shut off the pump in that event can turn a leak from a 2-3ft spray down to a trickle, which would potentially save a lot of wiring and work.

Just to clarify a few things, the system won't always be on and powered, and certainly not for more than a day or two at maximum, so keeping track of timing bugs after a month shouldn't be an issue, correct? Also, I'm not sure how much, if any, this would change the solution, but the time the button will be held down to release water can and will vary. I'd expect it to vary between maybe half a second and upwards of around 10 seconds. So just to make sure I'm understanding it correctly, the first two lines of code times how long the button was pressed for, and then adds 5 seconds to that time to determine when the pump should never be running, correct? Since we're dealing with times less than ~15 seconds total, we won't have to worry about the PumpStop value overflowing, right? If so, I'd still keep the overflow protection in there, just for redundancy.

Yeah if you know it won't run all the time and that it won't stay powered on for more than about a month at a time then it should be ok to ignore the millis() overflow. It might be good practice to still think about it and deal with it though, just in case you run for longer.

I actually omitted any button logic, so before the code above runs you'll want to detect that the button was released and then start code similar to what I showed. The first two lines are actually just finding the time the pump starts (after the button is pressed) and when the pump should stop. First it reads the current time counter by calling millis() and storing it in a variable called buttonPress--this represents when you detected the button press and started the pump. Then it computes when the pump should be stopped (if it wasn't stopped earlier) by adding time (5 seconds) to the buttonPress time--this is stored in the pumpStop variable. If you know the hardware will never run for more than a month at time without fully powering down and back up then you could at this point just have a simple check to look at when millis() is greater than or equal to pumpStop time. At that point you know enough time has elapsed since the button was pressed that the pump should be stopped no matter what. Make sense?

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

An alternate method would be to set up one of the timers to count clock cycles with an appropriate prescaler to form a clock that 'ticks' once per 0.1 second. Each 'tick' would fire off an interrupt that would increment some counter variable by one. At the start of your balloon filling step you'd zero out that variable and then in the loop() function you'd check it to see if it had grown beyond some value representing a reasonable amount of time needed to fill the balloon. If the tick counter indicates that the balloon hasn't filled within a safe timeframe you could shut the physical system down to a safe state.

If you don't really care about a possible bug every 49 days then just use millis() because it's way easier. If you do care about running for a long time this method would get around the 2^32 overflow problem.

One Legged Ninja
Sep 19, 2007
Feared by shoe salesmen. Defeated by chest-high walls.
Fun Shoe
I know this is the Arduino thread, but couldn't you just use a latching relay circuit that makes when you push the button to let water out, and breaks when the bladder is full? And also use a common well switch for the shutoff?

neogeo0823
Jul 4, 2007

NO THAT'S NOT ME!!

One Legged Ninja posted:

I know this is the Arduino thread, but couldn't you just use a latching relay circuit that makes when you push the button to let water out, and breaks when the bladder is full? And also use a common well switch for the shutoff?

I could, but it's only part of what I'm making. Even if it wasn't, that setup would keep pumping even if there was a leak, which is mostly why I'm hooking in the Arduino in the first place.

Here's a question about another part of it. I found some code which is supposed to help reduce the number of buttons I need, but I'm having trouble with it. Without modifying anything the guy posted, I can get the single-click and hold events to work, but the double-click one doesn't seem to want to trigger. I know it's not my wiring, I already checked that. I even tried wiring up a different board to see if mine was bad, but it produced the same results. Any ideas as to what might be causing it?

Sound_man
Aug 25, 2004
Rocking to the 80s
I would like to control the brightness of some 24 volt LED strips. I have never dealt with Arduino before but it seems like this might be a good project to get my feet wet. Looking at buying an Uno and this shield to deal with the PWM for the LEDs. http://www.adafruit.com/products/1429 I would need two DC power supplies, a 5V for the Uno and a 24 Volt for the LEDs. The idea is to have three pots and a few buttons to set the brightness and mode. I have some C experience and am comfortable working with electronics. Is there a better way to go about this? Am I missing something that will make this more complicated than it should be?

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

Sound_man posted:

I would like to control the brightness of some 24 volt LED strips. I have never dealt with Arduino before but it seems like this might be a good project to get my feet wet. Looking at buying an Uno and this shield to deal with the PWM for the LEDs. http://www.adafruit.com/products/1429 I would need two DC power supplies, a 5V for the Uno and a 24 Volt for the LEDs. The idea is to have three pots and a few buttons to set the brightness and mode. I have some C experience and am comfortable working with electronics. Is there a better way to go about this? Am I missing something that will make this more complicated than it should be?

Sounds like you're on the right track. Yeah that looks like a perfect board for controlling the strips. If you really want you could use a little DC-DC converter (or even just a linear regulator) to drop the 24V supply down to 5V for the Arduino: https://www.adafruit.com/products/1065 However it's fine and probably easier to use two supplies instead.

mod sassinator
Dec 13, 2006
I came here to Kick Ass and Chew Bubblegum,
and I'm All out of Ass

neogeo0823 posted:

I could, but it's only part of what I'm making. Even if it wasn't, that setup would keep pumping even if there was a leak, which is mostly why I'm hooking in the Arduino in the first place.

Here's a question about another part of it. I found some code which is supposed to help reduce the number of buttons I need, but I'm having trouble with it. Without modifying anything the guy posted, I can get the single-click and hold events to work, but the double-click one doesn't seem to want to trigger. I know it's not my wiring, I already checked that. I even tried wiring up a different board to see if mine was bad, but it produced the same results. Any ideas as to what might be causing it?

I would start adding some print statement to debug where the code is going and what's happening when you double click the button. Ultimately you just want to see how many button presses occur in a small sliding window of time and look for when that reaches 2.

politicorific
Sep 15, 2007
Quick question, about protecting raspberry pi gpio pins since I already burned one up due to a 6-8 voltage short.

Can I use 3.3v BZX79 Zener voltage regulator diodes to protect myself in the future?

Adbot
ADBOT LOVES YOU

Hadlock
Nov 9, 2004

http://fr.aliexpress.com/item/WeMos-D1-WiFi-uno-based-ESP8266-for-arduino-Compatible/32455782552.html

Arduino UNO form factor ESP8266, with 5v barrel adapter and micro USB port. Even the analog pin is in the right location. $10 shipped. Combine this with arduino ide support, it's an interesting idea. The pin logic level, I dunno, probably just 3.3v? I wish 5v legacy crap would just die but it's so ubiquitous so I guess the 328 is really good for that still.

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