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
Sagebrush
Feb 26, 2012

Two questions:

1) can you pull a +12v source from the car's power supply somewhere near your circuit, or do you need to have the arduino act as the power source?
2) how much current do you need on this 12v square wave?

Cause if the answers are "yes" and "just a little", all you need is a single NPN transistor rated for 12v (the 2N3904 is extremely common and rated for 40v@200mA) and an appropriate (~1k, 1/2 watt) resistor. Wire up the transistor with the collector to the 12v output line, the emitter to the 12v ground, and the base to the arduino digital output pin. The transistor just operates as an electronic switch, turning on and off the power supply at the same rate as the input square wave.

e: a transistor the like 3904 will start to fail at around 300-500 megahertz, so I think you'll be okay in that sense as long as your code can meet the proper timing.

Sagebrush fucked around with this message at 03:14 on May 22, 2013

Adbot
ADBOT LOVES YOU

Sagebrush
Feb 26, 2012

IANAEE but I'm pretty sure that a BJT transistor operating in saturation mode has no (or effectively no) voltage drop between the collector and the emitter. If there was a significant drop, any multi-transistor circuit with multiple possible signal paths (like, say, a computer) would be almost impossible to build. There will be a small drop between the base and the emitter, but you don't care about that in this case.

e: hey, check out what I found:

http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

Sagebrush fucked around with this message at 03:35 on May 22, 2013

Sagebrush
Feb 26, 2012

Do you have access to an oscilloscope? Hook it up and see if you're getting a clean signal from the car, then check and see that it's also going cleanly into wherever the arduino connects, and so on.

Sagebrush
Feb 26, 2012

Not sure if this is something that's come up in the thread before, but I just discovered it and I think it's awesome. Energia is a refactoring of the Arduino IDE and toolchain to make a version that's compatible with the TI MSP430 launchpads. I haven't played with it much, but all the Arduino code I've tried so far has run seamlessly on the MSP430 after adjusting for the proper pins and such. This is a super big deal for me because I really like the MSP430 series as hardware, especially for their highly accurate internal clock and extreme low-power sleep mode, but the TI Code Composer Studio toolchain is just abysmal. Being able to just treat it like a slightly different Arduino is amazing.

Also the development kit is $10, often goes on sale for $4.30, and actually comes with two microcontrollers and a better socket than the Arduino so it's easy to program one and then drop it into another circuit (or breadboard). It even comes with a USB cable, something the current Arduinos inexplicably don't provide. Pretty sweet!

e: and it's even compatible with the Stellaris launchpad, which costs $13 and runs an 80MHz Cortex M4...I have two of those and haven't even tried programming them yet, so this is great

Sagebrush fucked around with this message at 23:06 on Jun 9, 2013

Sagebrush
Feb 26, 2012

Also another thing from a couple weeks ago that I don't think has come up in the thread yet. I was working the Arduino booth at Maker Faire, and we were demoing some of the first production models of the Arduino Yun:



What's that? An Arduino with built-in ethernet and a USB-A port? What is underneath that metal shield? What is that U.FL connector for?

Why, it's a full Arduino Leonardo with an Atheros SoC capable of running the sort of Linuxes you'd have on a wifi router. Native Wifi and networking capability, and the two "sides" can speak to and control each other with a couple of libraries. SSH into your board! Trigger shell scripts from your sensors! Talk to your Arduino wirelessly without any bulky shields! Amazing!

There were a lot of people at the show making comparisons to the Raspberry Pi, which isn't quite accurate...the Yun doesn't have a GPU and the SoC isn't as powerful, while the RPi doesn't have built-in wifi or as many GPIO pins, and it uses more power (or so I've heard -- don't think full power specs for the Yun are out yet).

http://blog.arduino.cc/2013/05/18/welcome-arduino-yun-the-first-member-of-a-series-of-wifi-products-combining-arduino-with-linux/

Sagebrush
Feb 26, 2012

I picked up some Teensys and a miniature OLED screen for a project I'm working on. Runs great:

Sagebrush
Feb 26, 2012

If you're just getting started with Arduino, I'd suggest looking at the stuff on Sparkfun and Adafruit to begin. Some of it is a little expensive (Adafruit is cheaper), but there are two big advantages to buying, say, an LCD from Adafruit instead of buying the raw unit online somewhere: (1) it will come with a breakout board that doesn't require any SMD soldering or additional components (diodes, driver chips, resistors, shift registers, etc); and (2) it will have documented examples of Arduino code available, if not an outright code library that is basically plug-and-play.

A lot of people just strip open cat5 cable to make jumper wires but I personally find them a little too small for breadboard work. You don't want a wiggly wire making an intermittent connection because that's a pain in the rear end to track down. Here's a pack of 6 colors of 22ga solid wire; for 16 dollars and a wire stripper you can make like 500 4-inch wires that won't pop out of the breadboard.

(I do use cat5 for general hookups though because it conveniently has eight different colors in one cheap cable)

I agree with Bad Munki that you should get stuff in bulk or at least not from Radio Shack. When I'm just browsing for weird parts online, I generally check Jameco, All Electronics and Electronic Goldmine; if you need something specific, like a certain IC or whatever, Digi-Key or Mouser. I also have a bunch of little Adafruit things because she really makes good stuff.

Bad Munki posted:

Yeah, you can have a program on the computer listening/talking to the arduino over that serial port. Case in point: I saw one where a computer was listening to music and doing FFTs and such (much too heavy for an arduino to calculate) and then spitting the results via serial to an arduino, which was in turn using those results to drive a 5 meter ws2801 LED strip with eye candy. :)

For super easiness, check out the Processing environment. There are libraries readily available that will handle the communication between the two, you just spew/read data as needed and then do amazing pretty things in Processing because Processing is the poo poo for low-overhead (and/or one-off) graphics stuff. :)

Processing is a great environment to learn to code in, especially in parallel with the Arduino. Get a copy of that too. Talking back and forth the computer is trivial.

Also, Arduinos can too do FFTs completely on-board, though you'll be maxing out the chip's capacity: http://www.arduinoos.com/2013/03/plaindsp-part-1/

Sagebrush
Feb 26, 2012

You could easily do them on a Mega, though, with lots of room to spare. Or get a DIP m328 for $2.50, burn it with the FFT code and run it alongside your main board as a co-processor ;)

Sagebrush
Feb 26, 2012

wolrah posted:

OBD data, even at the rarely supported high rates, is probably less useful for any sort of position estimation than an accelerometer would be. Bluetooth shouldn't make it any worse, but it still won't be great no matter the interface.

OBD will at least give you a highly reliable speed value. You won't be able to measure geometric displacement (though you'll only barely be able to do that with an accelerometer anyway) but you can get the distance traveled pretty easily.

Sagebrush
Feb 26, 2012

saint gerald posted:

SO...now I want a project of my own. I want to build an RFID immobilizer for my project car, which will hopefully double as a G-meter. For this I'm going to need a couple of relays -- one to go on the car's ignition circuit, and one to go on the fuel pump line just in case. I think I want latching relays so they'll stay on (or off) regardless of whether the Arduino is powered. I know how to drive a regular relay: a transistor, and a diode to prevent a nasty spike as the magnetic field collapses. But how do you do it with a latching relay?

Same way, I think? Except that you send a single brief pulse (test, but probably 200ms is plenty) to toggle between the states instead of staying constantly on or off. The latching system is mechanical, just like those power buttons on stereos or whatever that push down and lock to turn on power.

Do consider though that this is really just security through obscurity...anyone can easily defeat something like this by finding the relay and shorting it with +12v. A well-hidden killswitch would be pretty much just as effective. If you're okay with that, though, go for it!

Sagebrush
Feb 26, 2012

echinopsis posted:

I don't mean to doubt you but I read on other places on the net that they basically are...

No, they aren't. The solid-state component that switches AC is called a triac. It works more or less the same way as a transistor though.

If you're going to be switching 110v for an incandescent light bulb, you'll ideally want to add in a zero-crossing optoisolator like the MOC3041 to protect your Arduino and prevent you from killing yourself.

Sagebrush
Feb 26, 2012

In the future you may consider something like an I2C port expander: http://www.digikey.com/product-sear...d=0&pageSize=25

Uses only the two I2c ports and gives you 16 I/Os for each chip. Several chips can share the same I2C bus as well. Probably the best way to get lots and lots of outputs with minimal additional hardware.

e: I'm not sure how fast you could turn those all on and off though...something to consider.

Sagebrush
Feb 26, 2012

That project is mostly mechanical in nature; the electrical and software stuff is pretty simple in comparison. If you can build the sliding carriage and the systems to open and close the liquor bottles, you're 80% there.

Sagebrush
Feb 26, 2012

I believe the Arduino will selectively choose the battery power over the USB power if both are available, actually. So it handles that situation but not in the way you want.

Someone correct me if I'm wrong, though -- I'm not completely sure of this.

Sagebrush
Feb 26, 2012

Easy to medium, depending on the type of motors. Can you see how many wires come out of each one?

Sagebrush
Feb 26, 2012

Bad Munki posted:

Just get an Uno. It's the most common board and the one 99% of arduino-based guides and tutorials will be using. I'd be shocked if it was lacking some capability you need that another arduino has.

I personally like the Leonardo these days because it has native USB HID support and uses a micro-USB instead of that big honking printer cable. It's also about $10 cheaper. The Uno is effectively the same board they've been making since 2006, though, so pretty much everything is guaranteed to work on it.

Sagebrush
Feb 26, 2012

Yeah, same. I love the teensys and end up embedding them in most of the projects I build where I can't be arsed to make a new PCB for a DIP chip. But I wouldn't recommend anyone buy one of those to learn on, because you lose all of the standardization of pins and the female headers that make an Arduino so non-threatening.

Sagebrush
Feb 26, 2012

Delta-Wye posted:

The problem ends up mostly being how do you get the temperature data to the arduino? Do you have a sensor in mind? The 'proper' solution I usually see is 4-5 embedded sensor nodes communicating with each other and/or a base station, so basically using multiple arduinos and wifi shields but that is getting expensive and complicated. Getting the physically spread out sensor data back to the single arduino may also be a pain in the rear end.

I think the proper solution is to get a bunch of those 2wire temperature sensors off eBay for $3 each and punch a series of holes in the walls and run a big spiderweb of cables all over the house, and use a $10 bluetooth module to talk to the nearest computer.

Sagebrush
Feb 26, 2012

Well, the nice thing about the Arduino environment is that all of the simplified functions like digitalWrite() and millis() are essentially just C macros. You can ignore those functions entirely and write plain AVR C into the Arduino IDE, and it will compile and upload just like any other sketch using the Arduino bootloader. In that case, any reference on AVR programming will give you all the information you need.

Furthermore, the nice thing about the Arduino board is that it can function as an ISP if you want to program standalone chips. I'd suggest picking up a handful of ATMega328 DIPs and maybe some Tiny85 and Tiny2313s (they're all like a dollar or two on Mouser) and looking into ArduinoISP. If you're writing plain C in the Arduino IDE and burning chips through ISP, you're basically just one step away from using a text editor and avr-gcc and avrdude like the pros do.

Alternately, if you don't care about the Arduino stuff at all and just want to program microcontrollers, you could always just buy a handful of ATMega DIPs and an inexpensive USB programmer https://www.sparkfun.com/products/9825 and go nuts with the usual toolchain.

Sagebrush
Feb 26, 2012

Theoretical question: are array accesses slower than other variable accesses? If so, by how much?

Basically I need to access the same element of an array multiple times in a function, and I know that the value won't be changing within this function, so I'm wondering if it is faster to assign the value to an int first and then access that variable later on, or just to access the array[value] every time? Or if it makes no difference at all?

Sagebrush
Feb 26, 2012

Delta-Wye posted:

What platform and compiler?

Check the thread title. ;) I have to say that I have no idea how to disassemble a .hex file and I wouldn't know what I was looking for if I did. I would imagine you're right, though -- the compiler (avr-gcc) is probably smart enough to recognize the multiple lookups of the same value and handle that efficiently.

Bad Munki posted:

If you know the value won't be changing within the function, why not just pass the specific array element by value and call it a day?

What's this mean?

For what it's worth, I solved the slowing down problem I was having -- it turned out to not be limited by memory access at all but by a code error, having one line inside a loop when it shouldn't have been. I was trying to bit-bang 144 kbps out a single 800kHz digital I/O instead of the 1.2 kbps that was actually needed and that obviously slowed things down. After fixing that it's working plenty fast. Still interesting to think about, though.

Sagebrush
Feb 26, 2012

Looks fine, assuming that things like the accelerometer and the LCD work properly. How much experience do you have with practical electronics (ie. building circuits, not just the theory)? Do you already have the basic prototyping stuff like a soldering iron, multimeter, breadboard, helping hands, jumper wires, decent benchtop power supply (mine is an old computer PSU), etc?

e: I guess that already comes with the breadboard and wires. It's a good starter kit for $24, yes. If I were to expand on that set, I'd suggest adding a few servomotors, hall effect sensors, thermistors/temperature sensors, and photocells.

Sagebrush fucked around with this message at 05:24 on Dec 27, 2013

Sagebrush
Feb 26, 2012

No, most multimeters with nothing connected to the leads will just float around some random value. Set it to voltage or resistance mode and touch the probes together, and it should drop to zero and stabilize in a few seconds. If it still floats with the probes touching, then the fuse is blown or the meter is broken.

I dunno what's in your microcontroller course, but no, the parts I've described and those in the kit are universal so even if you're using PICs or Cortexes or whatever you'll still be able to plug everything in. That's the nice thing about using a true general-purpose microcontroller instead of one of the lego kits or those sensor-block things etc.

Get a better soldering iron ASAP. You don't technically need one if you're just breadboarding, but it's a basic electronic tool and a temperature-controlled one is like a thousand times better than the cheap ones from rat shack. Check the main electronics thread for more info.

Sagebrush fucked around with this message at 19:37 on Dec 27, 2013

Sagebrush
Feb 26, 2012

Inside one of the female headers? Tweezers, I guess. Or maybe put a drop of hot glue on the hole with the pin stuck inside, let it sink in and harden, then pull it off?

Sagebrush
Feb 26, 2012

Combo posted:

One is a stepper motor on a slide like this video: It may be possible to scavenge this from an old printer?...though I'd probably have to come up with some way to control it.

The other, probably cheaper idea, was to put the cup on a lazy susan and use a servo to rotate it. My fear with that is that the servo will be too weak, but I don't know a ton about how powerful a servo can get.

Yep, you can almost certainly get a stepper, belt system and linear shaft like that from an old inkjet printer. Depending on how it's made, you might have some trouble getting everything mounted up correctly once you take it out, but fortunately the driving part is super easy. Thanks to 3D printers being a thing, plug-and-play stepper drivers are getting really cheap and common these days.

Guaranteed good quality for $16: https://www.sparkfun.com/products/10267
Anyone's guess, probably at least 3/5 of them will work, but it's 1/5 the cost: http://www.aliexpress.com/item/5pcs-lot-EasyDriver-Stepper-Motor-Driver-V44-A3967-Free-Shipping/1470167262.html

Those boards should work with steppers that have four, five or six wires. Four-wired steppers are the most common these days though.

As for putting a lazy susan on a servo: not the ideal solution. A large, powerful servo could drive the table around and index to different locations easily, but it can only rotate in a 180-degree arc. A continuous-rotation servo can spin 360 degrees but you need an encoder of some kind for your positioning to be reliable. A stepper motor, when properly sized and powered so it doesn't skip steps, is the best option for speed, accuracy and continuous rotation. Put a timing belt around the bottom of the turntable, run it onto a toothed wheel on something like a NEMA17 stepper, and use the same driver as above.

Sagebrush fucked around with this message at 06:30 on Feb 11, 2014

Sagebrush
Feb 26, 2012

I'd argue that knowing the position of the cup is pretty trivial if you have a designated spot for it on the wheel, and a drink mixer that whirls around like a gatling gun is way cooler than something that just bubbles liquid out of a tube into a funnel. But yeah, that would work too.

Sagebrush
Feb 26, 2012

There are some differences in the way the serial port is handled on the Uno vs. the Leonardo, and the Uno has the removable microcontroller, but that's about it. The Uno has the really annoying and poorly designed type-B USB port too.

If you want to program a discrete chip, though, you don't need an Uno to do it. Just buy the plain old chip (ATMega328 in 28-pin PDIP) from Mouser or DigiKey and wire it up with the ArduinoISP sketch (google it) and you're good to go. You can also program ATTiny85, 2313 and a few others this way.

Sagebrush
Feb 26, 2012

Captain Cool posted:

I was referring to the typo on the label in that picture. Doesn't give me high hopes of getting a genuine product.

If you buy cheap servos from a site in China it is virtually guaranteed that you are not getting a "genuine product." What you get may be equally functional or even come off the same production line, but it is definitely a ripoff in one way or another.

Sagebrush
Feb 26, 2012

Is your serial port set to the correct baud rate?

Sagebrush
Feb 26, 2012

If you're using A4 and A5, they have internal pull-ups, so the 4.7ks might not be necessary. I've used I2C for communication between two Arduinos and never needed external pull-ups.

e: actually between one arduino and one Teensy 2.0. I have no idea if the Teensy 3 has a similar setup or what.

Sagebrush
Feb 26, 2012

Looking at Wire.cpp I found this line

code:
        // On Teensy 3.0 external pullup resistors *MUST* be used
	// the PORT_PCR_PE bit is ignored when in I2C mode
	// I2C will not work at all without pullup resistors
	// It might seem like setting PORT_PCR_PE & PORT_PCR_PS
	// would enable pullup resistors.  However, there seems
	// to be a bug in chip while I2C is enabled, where setting
	// those causes the port to be driven strongly high.
	CORE_PIN18_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
	CORE_PIN19_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
So it automatically enables the pullups on A4/A5 for all of the Arduino-likes, but I guess the Teensy 3.0's MCU either doesn't have the internal pullups or there's a bug.

Sagebrush
Feb 26, 2012

jovial_cynic posted:

Anyhow, my first project was to tear apart the Blink tutorial that comes w/ the software and make a little 5-LED Knight-Rider light array.

The code is just an array holding the pin identifiers, a couple of for-loops that cycle through the LEDs, and that's basically it.

Are you using the delay() function or timers? delay() is bad because the command literally just sleeps the entire CPU for n milliseconds so you can't do anything else in the meantime. A better method is

code:
long timer;
int delay = 50; //50 millisecond timer delay

void loop() {
  if (millis() > timer + delay) {
    //do a thing
    timer = millis();
  }
}

This way the CPU keeps on running while the timer is going, and the computational load is very low. timer is a long type because the standard Arduino int is a signed 16-bit value, which will only get you up to 32.7 seconds before the timer overflows and breaks. I think there's also a way to fire a timer interrupt if you need microsecond-precision timing. If you're already using a method like this, ignore and carry on.

Sagebrush
Feb 26, 2012

Try using the 8mhz internal pscillator fuse settings first. I've had some problems with the other clock rates in the past.

Next, are you sure that you installed the cores properly? That also can be a mess sometimes.

Using a teensy 3.0 worries me, though. It's not got an AVR core, and it's quite possible that the ArduinoISP sketch doesn't work properly with the Teensy 3 at all. The 2.0 and the 2.0++ are the ones that are closest to a real arduino.

Sagebrush
Feb 26, 2012

Sorry, no solution to your problem, but rather an unrelated question.

Hypothetically, if you had a 12 volt line and you just wanted to figure out if it was energized or not, could you put it directly into an Arduino digital pin as long as you used a proper (1000+ ohm) resistor? Would external current control be enough to prevent the chip from burning up, or would having the higher voltage going in just totally screw with the logic?

Sagebrush
Feb 26, 2012

That's what I had planned to do, but I wondered if there was any technical reason you couldn't use a higher voltage provided you locked the current down. I could easily see some kind of charge leakage or something being a problem.

Sagebrush
Feb 26, 2012

Well, no, my application is more complicated than that. Was just wondering if I could save myself some time splicing into the line (the brake, taillight and turn signal lamps on a motorcycle)

Sagebrush
Feb 26, 2012

It's really hard to say without the actual code, especially if something like variable typing is causing the problem. Those things don't come across in pseudocode.

Sagebrush
Feb 26, 2012

What does digitalRead() do, exactly, that makes it so slow?

Sagebrush
Feb 26, 2012

If you just want to record the number of times the dog barked and grab the data once a day or something, so you can say "your dog barked 800 times yesterday" or whatever, all you need is the Arduino. Just increment the EEPROM every time the LED goes on, which you could measure directly if its voltage supply is between maybe 3.5 and 5.5 volts, or if not you could easily do it with an analog read of the pin voltage or a properly calibrated LDR stuck on the LED and wrapped in black electrical tape. You would plug in through USB and download the EEPROM value and reset it at whatever interval you like.

If you wanted to record the exact date and time to make a cool graph to show to the cops, you would need to hook up a clock module. The Arduino's crystal isn't accurate enough to keep time over more than a few hours. Then, since you're storing much more data than just an incrementing counter, you would also need an SD card shield/module of some kind. A little more complex for sure but not out of the question.

If you wanted to be a super cool hacker, I'd say get an ATTiny, wire it into the dog bark detector's 9v power supply with an appropriate divider, patch an ADC pin into the LED's positive leg to read it directly and store in EEPROM, and then wire in a button that you can press to have the ATTiny blink out a count of the last 24 hours' worth of dog barks in binary or morse code or something by hijacking the same LED you're reading. Hold the button down to reset for a new day. Total cost about $1.50 for the Tiny85 and some resistors and solder.

Adbot
ADBOT LOVES YOU

Sagebrush
Feb 26, 2012

Yeah, that's pretty much exactly the situation that a global variable is intended for.

Something I've always thought about re. EEPROM was a way to get it to only write data when the power supply fails. I thought about putting a supercapacitor (~0.1F 5v) across the power leads and probing the voltage occasionally to see if it's discharging, and if it is, write any important data to EEPROM and go into a brownout state. But you couldn't just do a standard analog compare, because that compares the incoming value to the chip Vcc, right? So you'd always have the same reading. Maybe some kind of little external RC circuit powered by the supercapacitor that you sample occasionally and compare to the chip's internal clock?

I imagine this is pretty much how cars with digital dashboards write their odometer values. Or maybe they do write the value every 0.1 miles and just move from one register to the next every 50,000 writes or so? Dunno.

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