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
babyeatingpsychopath
Oct 28, 2000
Forum Veteran


I went to Radio Shack, picked up an Arduino Uno, then took a dremel to an old Dreamcast Racing wheel, uploaded some stuff from this page.

$30 rudder pedals with individual toe brakes for my flight sim. $60 if my time is worth $20/hr.

As to the other stuff, I normally program PICs and MSP430s, and most of my stuff is in assembler, so program size and memory has never, ever, ever been a problem. Debugging and time to product, however, could be faster. This Arduino stuff is kinda backwards; throw lots of code at a small problem and let the huge memory cope with the bloat, overhead, and unused stuff, and just not worry because It Works.

Adbot
ADBOT LOVES YOU

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


JesusDoesVegas posted:

Ya, if you look at my code I used ==... I just typoed here.

Would a switch be faster?

It depends on how many comparisons you have and how good your compiler is.
If you have something that you're testing, and only one case can ever be true, you could write:
code:
if () 
   {} 
else if () 
   {} 
else if  () 
   {}
else
   {}
If your compiler is good, then it will turn all that into a big JUMP/BRANCH thing in assembly.

If you write
code:
switch ()
{
case :
  break;
case :
  break;
case :
  break;
case :
}
Then you've told the compiler to do it as a JUMP/BRANCH in assembly anyway. You may be smarter than your compiler.
If you wrote
code:
if ()
  {}
if ()
  {}
if ()
  {}
if ()
  {}
then the compiler can't be sure that each and every one of those cases can't run every time through the loop, and you'll get all the tests done. That may be slow.

This is getting into the programming in c of the device more than you probably like, but "small" devices like microcontrollers need a different way of looking at things; they don't have gobs of memory or fast cores, so you, as a programmer, have to know EXACTLY how your code is going to get compiled if you want good performance.

babyeatingpsychopath fucked around with this message at 23:10 on Nov 24, 2012

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


SomethingLiz posted:

Yeah, pretty much exactly like that. I'm looking into continuous rotation servos right now, it seems like they might be a good option because they're a little cheaper and don't require motor drivers which should cut down the price a lot. I'm not sure if they'd be strong enough though.

How much granularity do you need? 4 steps? 32 steps? A number of tick marks on each rod and an optical sensor, and you can use literally any directional motor.

Analog servos are also really cheap and reasonably easy to drive from 5v, although modifying "thousands" to be free-running would be tedious.

babyeatingpsychopath fucked around with this message at 01:50 on May 7, 2013

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


EDIT: Fixed! reset-en is cut, so it requires a manual reset every time a new sketch is uploaded. That's incredibly annoying.

I've got an older Arduino Mega board with a problem: it won't program over USB.

I've got an Uno that I programmed the ISP sketch onto, and now I can upload sketches using ICSP. However, I want to put that Uno back in the thing I took it out of.

How do I get this Mega working with USB again? It seems to be recognized when I plug it into the USB port; a device FT232R USB UART shows up. I got the newest version of the Arduino IDE, too (1.05), but that doesn't seem to have changed anything. Could the FTDI chip be fried? Arduino IDE bitrate different than what the FTDI is set up for? I don't see any options for setting COM port baud rate or anything.

The error is:
code:
avrdude: stk500_getsync(): not in sync: resp=0x00

babyeatingpsychopath fucked around with this message at 05:39 on Sep 15, 2014

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Cheekio posted:

I originally posted this to the electronics thread, and I think they're a bit out of my league. I have a nice 2A wall wort<>USB plug and an arduino project that simply uses too many servos. Assuming I can splice a USB cord correctly and wire it into the project correctly, can I just run the arduino and all the servos in parallel on the same input? That way the Arduino isn't trying to power all the servos.

The more I think about it, the more I oscillate between thinking it's really that easy, and then deciding I need some way to ensure the Arduino maintains 5V/500mA while the rest of the circuit gets whatever is left over from the original power source.

Is 2A going to be enough? Cheap wall wart power supplies get pretty bad at regulating their voltage near max current, and are also pretty bad at regulating when current changes wildly.

It is, in fact, just that easy to wire everything in parallel, but like they said in the other thread, put some largeish capacitors near the board to keep the power clean.

That being said, you can connect the arduino to the computer and all the servos to the power supply and then connect the ground pin of the arduino board to the - pin on the power supply. Clean power for all!

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Aurium posted:

Simply wiring voltage supplies in parallel is generally considered a bad thing. So I'm going to skip that. (but one of the possibilities might be what you're thinking of anyway).

I just want to clarify that I wasn't saying to connect the supplies in parallel. Just connect the grounds together to get both the servos and the arduino on the same voltage reference. This may create some ground current, but probably not. Wall warts are isolated supplies, and USB stuff usually is, too. If the computer is a laptop, then it's probably isolated.

I'm doing stuff with arduinos and servos. I've got my servos on a 9v supply and my arduino on a 3.3V. I've got a wire going from arduino "GND" pin to the - rail on the servo the power supply board, and everything plays nicely. Without that wire, the servos jump around sporadically, probably because the pulse doesn't rise high enough or fall low enough to reliably be a 1 or 0. Not that I've tried to probe voltages or anything; I just connected the wire and continued working.

babyeatingpsychopath fucked around with this message at 00:23 on Sep 17, 2014

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Cool Matty posted:

So I'm currently working on a project that will involve two (or potentially more) Arduinos communicating over a distance of ~30 feet or less. I don't wish to use wireless, since the area will be heavily covered in existing wifi networks, and reliability is more important.

So my thought was to run some sort of cable from the main arduino (a Mega), to each separate arduino (a Trinket or similar). Ideally, I'd like the cable to provide data (2 pins) and power (2 pins). The question is then, what would the best connector/cable be for this sort of usage? The power draw would be minor, likely in the range of 100ma or less per arduino box.

I'm a bit wary of using something ubiquitous like USB since it wouldn't really be a USB port. I'm worried some idiot will walk up and plug in their phone, expecting it to charge.

Right now I'm thinking something like a MIDI connector?

5-pin XLR is probably the most robust solution. It's used for all kinds of digitally-addressed lighting and stuff, so the cable is nice and shieleded, and it's good for tons of power. Looks like about $50 for 100' of cable with ends and $8 each for connectors.

4-pin XLR is also available, but it's 4x the price because it's uncommon.

Cheapest is gonna be ethernet plugs.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


TerminalSaint posted:

The button actually worked fine just routed from digital to ground. I scavenged some strips of surface mount LEDs out of an old keyboard and they work as intended wired up per the diagram, sans diode.

Which is odd, because the keyboard was feeding them 4.5 volts. I'm surprised they manage to light up on 3.3.

They've probably got a 1.6V forward voltage, so that's enough.

When I made a circuit like this, I just had the button connected directly to a pin and the LED connected to another pin that was turned on in software.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


PRADA SLUT posted:

I thought it was just a problem with the loop, which is why I only posted it. It's actually a gigantic program (but under the sketch size limits).

I now believe that it's actually a memory problem due to my arrays. My array is 1000 int's currently, which to my understanding is greater than the Arduino's RAM. I know how to slim it down, but before I do, is there a way to figure out how much memory various arrays take and what the Arduino can handle?

So, if YMIN and YMAX represent the boundaries of my servo's movement. yrange is the difference between the two, and yDefault is an int array which holds all these data. Would my loop look like this then?

(stripped-down code for length))

Is this on the right track? How do I initialize my array then? YMAX / INCREMENT? Would it be easier to make a quantized measurement and use that for everything (yrange / INCREMENT)?

So the arduino has 2k of SRAM. This means all your variables have to be less than 2048 bytes. 1000 ints is 2000 bytes.

Never ever ever use sparse arrays on an arduino. Try not to use floating point math, either, if you can help it. If you want it fast, precompute all the possible values you can.

Historically you do all this stuff with #define to make it simpler since (presumably) none of this stuff changes. Saves some memory and can give some good optimization.

C++ code:
#define YMIN 1000
#define YMAX 2000
#define INCREMENT 50

#define TOTAL_NUM_STATES ((YMAX-YMIN)/INCREMENT)
int yrange = YMAX - YMIN;	// Total unquantized range of motion
int yDefault[TOTAL_NUM_STATES];          	// Array which stores sensor data
memset(yDefault,0,sizeof(int)*TOTAL_NUM_STATES);
for(int i = 0; i < TOTAL_NUM_STATES; i++) {

servo.writeMicroseconds(i*INCREMENT+YMIN); // Move servo

(take measurements)

yDefault[i] = measurement;	// Put measured data into the array

delay(100);
}
At some point, I'm a bit confused why you're not using servo.write() to just output an angle. Then your whole range fits in 0-180.

babyeatingpsychopath fucked around with this message at 14:31 on Jan 31, 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!

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.

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.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Aurium posted:

...
even do[ing] something like us[ing] an regulator to get 3.6v for your 3.6v led, it'll develop problems)
...

I'd never really thought of this before. Why can't you use a regulator set for the correct voltage to directly drive an LED?

edit: Duh. Linear regulators are constant voltage; LEDs require constant current. Teach me to post without thinking about something.

babyeatingpsychopath fucked around with this message at 21:21 on Jul 31, 2015

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


politicorific posted:

Arduino Experts, how feasible would it be to build an intra-room pager system? (Or perhaps a multi-door doorbell might be a better description)

In my office I like listening to loud music when I work, it helps me to concentrate, however my boss and the other 5 guys in our 20 square meter office like to bug me all the time. I want to build a visual pager with flashing LEDs and buttons such as "Everyone" and "coworker -1 ". For example, if I press "porksmash" on my unit, the light for 'politicorific' on porksmash's unit illuminates like strobes or illuminates for 2 seconds.

I figure I could build this with an arduino, 2 shift registers (one for the LEDs, one for the buttons), a 433 MHz receiver, and transmitter. Living in Asia I can get Arduino Uno knock offs for $3/piece. I figure I can get the whole thing down to less than $10.
I pretty much only need to transmit 4 bits.
For example my device ID is 0001. Porksmash's is 0010. 1111 - could be a broadcast message. However, I've read that 433 MHz parts have some delay issues - I would like this to be as delay free as possible.

Are there any projects out there similar to my idea?

TBH, this sounds like a perfect job for an ESP8266 and the arduino toolchain. Everything's done in wifi. The device address can be an IP that you stick over somewhere. The ESP speaks IP already, so you just send a ping or whatever and the thing on the other end blinks. No worries about 433MHz stuff.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Combat Pretzel posted:

So yeah, the input pins of the Arduinos don't draw unnecessary current, do they? Say if I connect an analog pin with a voltage divider to a RC battery (something with 5Ah capacity that can output 20-40C), this will not blow up my board, right? In regards to implementing voltage sensing and such...

In normal digital or analog input mode, the input impedance is about 10MΩ. The input pullup resistors are 20-50kΩ on most boards.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


SkunkDuster posted:

Why am I running into a 25 character limit with the liquidcrystal library when scrolling? I got the sunfounder super kit with an Arduino UNO and LCD1602 and my test messages shifts the cursor up or down a row every 25 characters even though I am telling it to shift at 33. If I increase it above 33, it still shifts at 25 and just adds garbage characters at the end. For example, I get this:

code:
HELLO YELLOW! HELLO YELLO
                         W!abcdef
code:
                         RE JELLO
SHAKE YOURSELF LIKE YOU A
I suspect it has something to do with lcd.scrollDisplayLeft()

my loop looks like
code:
lcd.setCursor(15,0);  // set the cursor to column 15, line 0
    lcd.print(array1);
    for (int i = 0; i< 33; i++)
    {
      lcd.scrollDisplayLeft();
      delay(tim);  //wait for 250 microseconds
    }
with your code, and I get the same problem.
To contrast, using the same LCD library, I turned on lcd.autoscroll() and scrolling works like a champ.

edit:
I used lcd.setCursor(0,0) and lcd.setCursor(0,1) and there's no line tearing, so that's definitely the problem.

babyeatingpsychopath fucked around with this message at 22:16 on Nov 28, 2015

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


SkunkDuster posted:

Can I see the code you used for autoscroll? I tried it and it is still jumping at 25 characters.
code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 

void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.autoscroll();
}
void loop() 
{ 
  static char message[] = "A message";
  static int mesglen=sizeof(message)-1;
  int i=0;
  lcd.setCursor(0,0);
  for(;;)
   {
     lcd.write(message[i]);
     if(++i==mesglen) i = 0;
     delay(250);
   }
}
Note that if instead of lcd.setCursor(0,0), I put in something else, then the odd behavior happens. There's stuff going on in the background of the lcd library.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


A Yolo Wizard posted:

anyone here messed with making custom device descriptors for teensy 2.0? I've done it with 3.0 boards, but it seems completely different for the 2.0. I just want a keyboard without the sd card initializing

I've made custom device descriptors before. What's the chip on the teensy? Atmega32u4? Should be the same hassle as the Atmega8u2 on the Unos.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


TheresaJayne posted:

Wonder if anyone can advise me how to sort this problem out - I can solder and program but Circuit Diagrams are just not in my stupid mind.

I plan to use a nano with Temp Sensor to control a PWM computer fan (4 cable jobbie)

The background, A yacht, The fore cabin heating is a Computer fan blows air through a heat exchanger and into the cabin.

I want to have a temp sensor that will slow the fan to min speed as temp reaches the desired temp.

Pot on front as thermostat setting
the power to drive the fan and the nano is the 2 core power from the batteries (12v)

How should i wire it up where it will not blow the nano?

4-wire fans are pretty awesome. The TACH wire provides 1 or 2 pulses per revolution; it provides a ground to the voltage you supply it. You should be able to read from it with your arduino's pin set to INPUT_PULLUP. The PWM input is pulled high and expects a PWM signal at ~25kHz that pulls that pin low. +V and GND are obvious.

Because the PWM signal expects to be grounded to modulate speed, if you don't connect anything to that pin, the fan runs 100% all the time. Once you can read from the tach, you should implement a PID controller for fan speed vs temperature.

The hard bits are going to be calibrating your temp sensor and getting your PWM frequency right.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


The Dark Project posted:

Yeah, that's what I was thinking. If I had my hands on a schematic of the kinds of gears they used, the arrangements and timing etc, I could probably look to making a smaller scale version for myself. I can't get a hold on anything like that, so my next thought was to use a series of stepper motors programmed in the right sequence to replicate the motions being carried out on the full sized machine.

It might be something I could sell, but mostly this is for me since I make a lot of scenery, and buying brass etched stuff is expensive and not as good looking, and I am constantly stabbing myself making the smaller scale correct stuff for myself. It does intrigue me though as to whether or not it is possible to do. I like exercising my brain with "how-to's" like this.

It's absolutely possible to replicate a cam-and-gears machine with steppers/servos/actuators. There's no question about that. It's even possible that the controller could be some flavor of arduino.

The actual problem to solve is the mechanical actions needed to perform the barbed-wire-making. Once you have those mechanical actions, then you need to build a machine that can perform each of those steps. Then you need to automate that process, with all that involves.

Lathe first, motorized lathe second, CNC lathe third.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


General_Failure posted:

Hey people!
Sorry to do a tl;dr on you, but I intend on reading this thread fully when it's a little more useful to me. For that I need some help. I'm looking to buy a cheap Arduino like thing from AliExpress or similar. Honestly I don't really know what I'm looking for.
I'm coming to you from "the other side". Not death, but I've always designed built my own boards and written my own firmware but would like something cheap and cheerful to throw at things when I need to quickly solve a temporary problem.
I have one right now that I've brought up in the blue smoke thread. I need something to drive a stepper for an egg tray in an incubator. That's just one example though. Pretty much just random data logging, sensing and actuating stuff.

I'm not a brand whore. Ie don't care about architecture family etc. but decent toolchain support in Linux is a big plus.

Could someone please point me in the right direction? I'd like to order one and one of those big packs of 30-ish daughterboards they have ideally. I'm doing this on a budget of as close to $0 as possible.

Could someone please offer some suggestions on things that work? Thanks. I've looked and I'm kind of daunted.

You just need to drive a stepper.

I went onto amazon, found something that ships prime, and hit go. I see a $.90US one on there. I think mine were $10 for 3, and they're fine.

Use four pins from that and four transistors in an h-bridge to drive your stepper. Done. Solved problem. The arduino IDE works in linux.

Of course, you could also just get a stepper driver breakout (pololu, a4988, etc), and wire up a 555 to throw a pulse at that thing's "step" pin every so often, with some limit switches to switch between forward and reverse.

babyeatingpsychopath fucked around with this message at 01:19 on Jan 14, 2016

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


General_Failure posted:

Didn't realise there were actual breakout boards. What's this something you are speaking of? Also I'm in Australia so Amazon doesn't always work out so well for me.

Look at stepper driver boards. They're commonly available on 3d printer sites. The commonest are Pololu-brand A4988s and pin-compatible clones using other driver chips. You feed in stepper motor voltage (12V, 24V, 9V, whatever), logic voltage (3.3 or 5V), then you assert three pins to make the thing go: Enable, Direction, and Step. Every pulse on the "step" pin moves the motor one step in "direction" if "enable" is on. The board handles current limiting and all kinds of other great stuff to make these braindead simple to use. There are typically jumpers on the board to enable 1/2, 1/4, or 1/8 microstepping for the A4988s, and 1/16 and possibly 1/32 stepping for other chips. This means if you've got a 200steps/rototation motor and you jumper the board for 1/8 microstepping, you get to send 1600 pulses to get one revolution. Downsides are more current draw and lower total torque.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


One Legged Ninja posted:

Edit: Third and fourth question. I'm setting the four output Row pins to HIGH, setting the five input Column pins to INPUT_PULLUP, then pulling each row LOW in order and looking for input LOWs. (I had some bad floating issues going the other way.) Is this an acceptable way to do it, or should I work some external pull down resistors into my intermediate connection board and do it my initial way? Also do I need current limiting resistors on my four Row lines, or will it be ok without them?

This is the way I did it.
my main function looks like
code:
loop()
{
	pinMode(SELECT1,OUTPUT);
	digitalWrite(SELECT1,0);
	button1=digitalRead(B1);
	(7 more buttons here)
	pinMode(SELECT1,INPUT);

	pinMode(SELECT2,OUTPUT);
	digitalWrite(SELECT2,0);
	button9=digitalRead(B1);
	(7 more buttons here)
	pinMode(SELECT2,INPUT);
	
	etc.

	if(serial.available())
		{
		serial.read()
		serial.write(button1);
		...
		}
	
}
It works for 24 buttons and 4 axes just fine.
Basically, the thing is updating all the buttons every loop as fast as possible, but it only dumps its data when the other end asks for it. It's possible there are some race conditions or something, and that it's ridiculously inefficient, but w/e.

The software on the other end isn't super intelligent, either; basically just takes in byte values and translates them to useful stuff, then dumps that out to a UDP port for xplane.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


VelociBacon posted:

Anyone have an idea where I could find code that would make an LED behave like a flickering candle? Thanks.

A good hack I saw a bit ago just played "happy birthday" to an output, and hooked that up to an LED. It was flickery-enough. If you want something more actually true-to-life with random number generators and stuff then that's also an option.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


huhu posted:

The code says vid should be 0x26 and pid should be 0x42. What could be the issue here?

Well, if the VID and PID don't match what an OV2640 are, then you've got a counterfeit shield, I'd guess. Or there's a configuration error somewhere. You've gotta figure out where those VID and PID numbers come from. 0xAA, 0x13 may be useful information to you if your code is sending someother command to the module than "what's your VID/PID?"

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


SkunkDuster posted:

Arduino Uno questions:

code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}
1. Here's a bit from the LCD Hello World code. I'm learning that you have your setup function and your loop function but then I see examples like the one above with lines of code that aren't part of either function. How do you know whether to put non-looping lines of code on their own or in the setup function?

2. I'm working on a project that uses a 4 hour timer. Accuracy is not that important +/- 5 minutes is fine. Do I need the Arduino board for timing, or can I pull the Atmega chip off and solder it directly to a prototype board after I load the code?

3. Is there a way to set the pins according to the physical pins of the chip instead of the board numbers? For example, if I was using the Uno board and I wanted pin 10 to be an output, I would write...

code:
  pinMode(10, OUTPUT);
...but pin 10 on the board is physical pin 16 on the chip. To keep things simple, I'd like to write the code to reflect the physical pin of the chip.

4. If I have 3 functions in my loop, A, B, and C, is there a way to exclude functions until a condition is met? For example, I'd like to have 'A' say "if button 1 is pressed, loop function B and only function B". 'B' would would say "if button 2 is pressed go to Function C and loop that, if button 3 is pressed go back to function A". I'm assuming it can be done, but I don't even know what to Google search for to get me headed in the right direction to figure it out. If anybody remembers BASIC, I'm looking for the equivalent of the GOTO command.

1. That "line of code" is a variable declaration in C++, it's "code outside of a loop/function" in only the strictest and most basic sense of the term, but just fine in a high-level object-oriented language.
2. Yes. Look into fuse bits and using the internal clock, and realize that you're at half or quarter Arduino clock speed.
3. Learn #define and .h files with #include, and love them. If this makes literally no sense at all, read up on "C" programming language
4. If you're looking for BASIC's GOTO, then you need C's switch()
C code:
buttons=digitalRead(BUTTON_A)<<2|digitalRead(BUTTON_B)<<1|digitalRead(BUTTON_C);
switch(buttons)
    {
    case 4: // button A only
       //some stuff
       break;
    case 2: // button B only
       // some stuff
       break;
   case 1:  // button C only
      // some stuff;
      break;
   default: // more than one button was pressed, i'm gonna give up.
      ;
   }

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Fanged Lawn Wormy posted:

I'm trying to remember if this is a thing I've figured out before or not...

I'm working on creating an object that uses a serial port as part of it's workings. I'd like to make it so that I can tell the object at initialization which serial port to use, since this is going on an Arduino Mega, and I'm most likely going to be using multiple of the same object (thus why I am making it an object).

So, I'm trying to figure out how I do that?
for example, I want to have something like this:

handyObject.init(serialport, ledpin, foo, bar);

where serialport is a value that tells it to use port 0, 1, 2, or 3 during it's other functions in the loop.

I hope this is clear enough, I feel like there are words for what I'm describing but I can't quite recall.

Are you talking about a constructor with values?

class handyObject {
public:
handyObject(int port, int pin, int foo, int bar);
handyObject(int foo, int bar); // for when you just want to use default ports
}

My apologies for horrible C++. I use other languages for OO stuff, and do everything on microcontrollers in standard C.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Captain Hair posted:

Sticking stuff to the glass is kind of a no, because it gets swapped around and rotated after cleaning, so I'd have to do each corner. The more I look at the problem the more I feel micro switch with long lever is the way to go. Cover the metal arm with heatshrink so it doesn't scrape the glass. Could work.

You're looking for a limit switch. The industrial hard plastic operators and NEMA enclosures with weatherpoof wiring are probably overkill, but long-lever microswitches are a thing.

I'm not sure how your doors are rigged; a picture would be very helpful.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


scandoslav posted:

I'm stuck on killswitch relay selection. It's my understanding that the motors on the RC crawler I'm using as a chassis can draw ridiculous amps when stalled. My ESC is rated for 60 amps continuous, 360 amps peak. I have not been able to find relays (at least on the sparkfuns/polulus/etcs.) that can handle that sort of VDC current, and the ones on digikey that can are hundreds of dollars. I'm assuming the worst case scenario of a glitch/bug holding a stall long enough to fuse an inadequate relay before the ESC's automatic overheat protection kicks in.

Clearly there are ways to do this. The esc has a swtich, after all. How is my near-complete ignorance of electronics biting me in the rear end this time?

Do you want a killswitch or just overcurrent protection? A fusible link or a slow-blow fuse should be fine. Otherwise, you're looking at industrial contactor territory; they've got beefy springs to open contacts quickly, and arc chutes to throw the arc into catch cans so the arcs don't melt stuff.

Look into medium-amp relays. I know there are 12-24VDC controlled relays that switch 24VDC loads@30A and aren't all that large. If you're doing killswitch-style stuff, then you just need the interrupt rating of the relay; that's what it can handle a couple of times without welding itself.

Just looking at my maintenance manuals, ANL-xxx series current limiters or MS28937/MS28938 (bussman ACH series) fuses will hold crazy current for a little bit, then pop. Current limiters are slower-blow than fuses, but fuses have a faster response time to high-current shorts. Unfortuantely, my pubs are for aircraft manufactured in the 70s and 80s, so the relays are NLA by that part number, and I don't have the logins to get to the parts xref database to figure out who makes them now.

babyeatingpsychopath fucked around with this message at 03:28 on Jun 7, 2016

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


huhu posted:

I want to be able to send text to an Arduino and have it write on a paper surface with a marker. My basic idea is to use two stepper motors to control x/y motion along with a system to mount the motors, markers etc. The part I'm completely lost on his how to create a way to send instructions to the Arduino. My original, bad idea, was to create a library that defines what each letter would look like (an O would be, move right 1, up 2, left 1, down 2). However I've seen much more complicated designs that can water color, print in cursive, etc. What should I be reading up on to get started?

You're basically implementing a 3d printer/CNC router that renders its own gcode on the fly. This isn't all that hard if your character set is limited and fixed. Look at shapeoko/RAMPS for already-built-and-implemented arduino shields that understand gcode. From there, you can write a glorified wrapper that reads text and sends gcode strings to the base firmware to draw on paper.

babyeatingpsychopath fucked around with this message at 04:36 on Jun 26, 2016

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


What are you trying to do?

Serial communication is really very very simple.

Program A sends a string of characters to the arduino, which reads them. If program A is well-behaved, then you can just read a specific number of characters with the arduino every time. If not, then you loop over a state variable (while (Serial.CharacterAvailable())) and consume characters until there are no more, then do something.

Treat it like reading a series of strings from the keyboard or wherever, if that helps you.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Captain Hair posted:

As genius as that is I really need all ten buttons easily available. It's running a couple of lcds so I did consider using an lcd keypad with osd, but it's much simpler for my user if she just has all options available as buttons.

I think I'll just go the resistor per button route, maybe make up a spare board that she can swap out in future if a button fails. :)

You can get to 4 pins with charlieplexing if you like diodes.
edit: you can use (n * (n-1)) buttons with n pins. 3 pins = 6 buttons, 4 pins = 12 buttons, 5 pins = 20 buttons. If you use LEDs as your charlieplexing diodes, you get lit buttons for free. You don't even (necessarily) need to put a button on a state; you can just have a diode there, and if you want it on, then put it in your polling loop.

babyeatingpsychopath fucked around with this message at 02:25 on Aug 13, 2016

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


General_Failure posted:

I mentioned it in passing in the magic smoke thread but I'm putting some hard labour into getting one of those little red fan modules working again for my little boy. A few days ago his Arduino Uno refused to turn the fan again beyond a twitch. I had a look at it today and the 5v regulator seemed to gave gotten flaky in a weird way. Any load seemed to result in a pretty good short circuit between VIn and GND. It still seemed to function on it's own but just using USB in avoided the bad smell :( I modified the proto / breadboard shield we were using to have a 5v linear regulator and input but it was too little too late. RIP Uno.

So I've given him mine essentially and I've been hard at work trying to get one of the damned fan modules to work properly.



Here's where I'm at. The only thing the Arduino really does is toggle one of the inputs to the H bridge when the button is pressed.

It took the 4700uF cap to get the fan to start properly instead of a rapid reboot loop as the uC got curbstomped by the startup current of the fan. The regulator gets hot too. What the hell sort of fan is this???
So before I hand it over I'm going to have to change the "debounce" example sketch (OK I was being lazy) to use PWM for an acceleration curve and perhaps cap it at about 80% duty. Thoughts?

I wasn't testing it on the stainless bench so don't worry. I'm not quite that silly, usually.

Why not power the h-bridge from a completely separate 5V supply and not run all that current through the dev board and its linear regulator?

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Sagebrush posted:

Using switch/case instead of chained conditionals is equally valid, yeah. I don't know which one is more cycle-efficient -- I haven't really run into a situation where it mattered. I bet they compile into pretty much the same thing.

Looking at the generated code, a case is slightly more efficient. The case evaluates into a jump table, and the chained conditionals are all evaluated. You'd have to do some serious testing and actually NEED to find optimization for that to be worthwhile. I like doing things like this:
C code:
switch(mode)
{
case 1:
case 2:
case 3:
case 4:
   some stuff;
   break;
default:
}
When something like this compiles with max optimization, the compiler will do some clever stuff with jump table generation and can unroll cases and defaults, especially if your mode value is an enum.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Spazzle posted:

The strips are just individual ones linked together. I think you can actually cut singles off and use them.

If you really only want one pixel you could set the strip length to one.

I also prefer the fast led library. If I recall the default neopixel library was laughably slow.

I was using the fast LED library for strips, but now I've got some panels. Is there an equivalent to fastLED for neoMatrix?

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Fanged Lawn Wormy posted:

I have used fastled with the adafruit matrices - they work just like 8 strips of 8 pixels daisy chained like reading text, left to right, top to bottom.

Also, if you end up doing multiple pixel strings, follow the neopixel guide advice if putting a resistor in series on the data pin. Something about writing multiple pixel strings on multiple pins can cause the first pixel in line to fail. I've found a 470 ohm resistor fixes that right up.

Yeah, I've got a bunch of individual strips, and they're wired differently than the tiles.

I'm using the adafruitGFX library to draw lines and pictures and whatnot. It's nice that the neoMatrix library can just take my arbitrarily-wired strings and make them work right. I'd really prefer to not rewrite a graphics library in assembly for yet another platform.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


unpacked robinhood posted:

I'm trying to output unmodulated IR codes when pressing a button, which works half the time.

I suspect it's got something to do with the state of the counter when hitting the button but so far I haven't been able to fix this.

This is what the output looks like:



Here's my code, trimmed for readability. Pressing the button calls transmit()

How do you correctly start and stop pulses at the correct time in this mode ?

Here's my take on your code. I unwrapped the loop for clarity. I also like the "for(;test;);" construction instead of do;while(test);
C code:
void pulse(int high, int low){
	//inputs: high, low, number of clock ticks spent in each state.
	//outputs??? I have no idea when the output is set.
	OCR0A=high; 					//i assume we're setting some clock register
	//set some output pin high here?
	for(;(TIFR&1<<OCF0A) == 0;); 	//and then waiting for it to time out
	TIFR=1<<OCF0A; 					// then resetting the interrupt
	OCR0A=low; 						// then doing it
	//set some output pin low here?
	for(;(TIFR&1<<OCF0A) == 0;);	// over again
}
void sendCode(uint8_t code){
	//inputs: code, 8-bit code we're sending
	TCNT0=0;
	uint8_t mask=0x80;
	while(mask)
	{
		if(code&mask) // check the bit at the mask position
			pulse(82,184); 	// if 1, long pulse
		else
			pulse(80,50);  	// if 0, short pulse
		mask>>=1; 			//shift mask down.
	}
}

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


unpacked robinhood posted:


code:
for (int Bit=15; Bit>-1; Bit--)
The first two pulses of the address part (highlighted in orange) go missing. It makes no sense to me. What am I missing ?

try
code:
for (uint16_t Bit=0x8000;Bit;Bit=Bit>>1)
and see if it gives you the same result. 1 << 17 should roll off the end of a uint16_t.

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


unpacked robinhood posted:

I edited in your loop declaration and changed the condition right after.
It's more elegant but it still either loses 1 or 2 pulses at the beginning, or introduces one short extra glitchy pulse at the end.

This isn't a big deal because my previous code still works better, but I admit it's not satisfying and hacky.

That just means it's not the for loop initializing that's causing your bit problems. Your program is just not sending one or two bits to begin with. Starting upshifted 17 just means you don't send the bits you're missing, so you always start correctly. Look elsewhere for this problem.

Adbot
ADBOT LOVES YOU

babyeatingpsychopath
Oct 28, 2000
Forum Veteran


Sockser posted:

I'm looking to run somewhere between 100-150 neopixels off an arduino.

This is going to be controlled from a game I'm coding up in python, and I basically want the LEDs to just chill in a standard sine wave pattern, and just switch colors depending on some events in the game.

I assume I just need to send some serial data to my arduino and then parse it from that side, yeah? Could send it as a series of .... 12 bytes, I guess, to preserve some latency, or I could define the colors as an enumer and just send over a single byte. Is there a simpler way to do it?

Also, shouldn't matter which board I use, right? I've got a couple teensy's and an Uno and a Mega sitting around, probably just gonna use the teensy and solder it to a perf board

I've run 300 neopixels with a single uno; any board will work. You need to use the fastleds library for that; you start to run out of timing to do anything else with that many pixels. Also, the strips get REALLY HOT if you just have one power connection at the end. Split the strings.

If all you're doing is changing the color with serial data, then 3 bytes is plenty to send a color. But that's probably not where your bottleneck is, so sending "0xFFEE00" over serial and parsing it is likely easier to understand and code, and not where your code is going to be spending most of its time.

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