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
unpacked robinhood
Feb 18, 2013

by Fluffdaddy
Today in babby I'm trying to have three(3) buttons work with my attiny.
Due to the specific layout of the circuit I'm hooking too I can't simply have a button between ground and a pin on the mcu.
I've associated each of the buttons to an arbitrary number to synchronize the port setup before polling a specific button.

Circuit:


This is my current code:

code:
uint8_t mute_history=0;
uint8_t volp_history=0;
uint8_t volm_history=0;


/**
 * sets up ports to read a specific button betwenn 0x01,0x02,0x04
 * returns 1 if the selected button is pressed
 */
uint8_t read_btn(uint8_t  curbtn){
	uint8_t ret=0x00;
	if (curbtn==0x01){
		DDRB &=~_BV(PB2);//PB2 en entree
		PORTB |=_BV(PB2);//pull-up actif
		ret= ( (PINB & _BV(PB2)) == 0 );
	} else if (curbtn==0x02){
		DDRB |=_BV(PB2);//PB2 en sortie
		PORTB &=~_BV(PB2);//PB2 a 0
		DDRB &=~_BV(PB0);//PB0 en entree
		PORTB |=_BV(PB0);//pull up sur PB0
		ret= ( (PINB & _BV(PB0)) == 0 );
	} else if (curbtn==0x04){
		DDRB |=_BV(PB0);//PB0 en sortie
		PORTB &=~_BV(PB0);//PB0 a 0
		DDRB &=~_BV(PB4);//PB4 en entree
		PORTB |=_BV(PB4);//pull up sur PB4
		ret= ((PINB & (1<<PB4)) == 0);//lecture de PB0
	}
	return ret;
}

uint8_t debounce(uint8_t  *button_history,uint8_t  curbtn){
	uint8_t pressed = 0;
	*button_history = *button_history << 1;
	*button_history |= read_btn(curbtn);
	if ((*button_history & 0b11000111) == 0b00000111) {
		pressed = 1;
		*button_history = 0b11111111;
	}
	return pressed;
}

This part gets called regularly to poll buttons, and the part I'm having trouble with. For example

code:
ISR (WDT_vect){
	if (debounce(&volp_history,0x02)==1){
		PORTB ^= _BV(PB3);//flip led 1
	}
}
Will correctly check the one button I arbitrarily associated with 0x02, and toggle the led.

However:
code:
ISR (WDT_vect){
	if (debounce(&volp_history,0x02)==1){
		PORTB ^= _BV(PB3);//flip led 1
	}
	if (debounce(&volm_history,0x04)==1){
		PORTB ^= _BV(PB3);//flip led 2
	}
}
Will only check and act on button 0x04.

There's something really dumb I missing but I don't see what ?

e: "fixed" by adding a bunch of nops before reading the pin status in the read_btn function

unpacked robinhood fucked around with this message at 16:17 on Mar 10, 2017

Adbot
ADBOT LOVES YOU

rawrr
Jul 28, 2007

UberVexer posted:

Adafruit has a ton of projects in their learn system that are structured well, commented well, and are useful examples of how libraries work.

Sagebrush posted:

I'd start with the Adafruit stuff 100%.

Thanks - turns out the Adafruit sous vide project is extremely close to what I'm trying to do, and it has good examples for using eeprom and state machine which is super relevant/helpful.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
I'm looking into making a time code generator with a Due for shits and giggles and need to bone up on how to do the programming side of the serial signal shaping (got lots of diagrams/info on the standard already thankfully). Does anyone know of a good reference? Searches with serial and arduino just get tons of really basic poo poo no matter what else I add into the search terms.

huhu
Feb 24, 2006

Parts Kit posted:

I'm looking into making a time code generator with a Due for shits and giggles and need to bone up on how to do the programming side of the serial signal shaping (got lots of diagrams/info on the standard already thankfully). Does anyone know of a good reference? Searches with serial and arduino just get tons of really basic poo poo no matter what else I add into the search terms.

What is a time code generator? If I should know I probably can't answer your question then.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
It's pretty much exactly what it sounds like, you feed a circuit time from a source like GPS and it spits out a serial code that sensors or cameras can sync to so all your data has a consistent time stamp on it.

Here's some more info, everything looks from their diagrams like it should be doable with a serial signal with I -think- 1 start bit, 8 data bits, and one stop bit.
https://www.meinbergglobal.com/english/info/irig.htm

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
Looking over some stuff maybe what I really need to do is find some good info on binary operations and let the arduino handle the rest. I'm going to do some searching after work but any recommendations for guides is appreciated.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

What do you mean by serial signal shaping? If it's what I'm thinking, then your microcontroller will have a serial UART that does that for you. The output of the UART is just pulses at 3.3 or 5V, so you then also need an RS232 transceiver to output at line level.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
I guess I mean setting everything up since it's clear this doesn't use 8N1 serial. Fortunately looking over the data sheets on the spec it looks like it is a 5v signal for the connection I intend to use and not the RS232 level.

ed: maybe 9N1 since there are 9 bits of data, no apparent parity, and every 10th bit is a zero for position identification.

Parts Kit fucked around with this message at 00:12 on Apr 8, 2017

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Sorry, I was skimming and didn't realize what you were doing. You might be able to get a UART to do what you need, but it might not be flexible enough to accommodate the different width pulses. At those speeds you could probably just bit bang it. There should be an SPI peripheral on the uC used by the arduino, which you might be able to use as an alternative to the UART. I think it would be limited to 8-bits output at a time with an AVR, you might be able to use it repeatedly to get a continuous stream.

Fanged Lawn Wormy
Jan 4, 2008

SQUEAK! SQUEAK! SQUEAK!
I recently got my first SMD Design back!


It's a variant on a through-hole board I designed previously. It's an Arduino shield which can be used with the Arduino Mega to give RS232 and RS485 communications to the serial ports. It also has a header for connecting to Opto22 relays, and 3 extra LEDs for indication.

Lessons learned on the prototype:
1) D+ and D- were switched, and some other silkscreen stuff I didn't catch.
2) LEDs were not of consistent brightness, but I'm not entirely surprised. I knew there would be mistakes so I ballparked what I thought might work. The LEDs are standard elecrow parts (R, G, and B smd leds), so I've got spec sheets form them now and will tinker and even out the LEDs to make them closer.
3) Using a stacking header upside down to connect the ICSP pins doesn't looks as nice as I'd like (left them out here). Maybe I'll just put a hole like I did for the reset, pin 13 LED, and RX/TX leds.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr

taqueso posted:

Sorry, I was skimming and didn't realize what you were doing. You might be able to get a UART to do what you need, but it might not be flexible enough to accommodate the different width pulses. At those speeds you could probably just bit bang it. There should be an SPI peripheral on the uC used by the arduino, which you might be able to use as an alternative to the UART. I think it would be limited to 8-bits output at a time with an AVR, you might be able to use it repeatedly to get a continuous stream.
Yeah, looking more and more like bit banging is going to have to do for now. So I'll just dig through the Software Serial code and see what I can figure out. Thanks!

politicorific
Sep 15, 2007
Captain Cool, thank you for your help (5 months later) with my ACH164 LED array that I pulled out of a dead switch. I missed your post the first time around. This point was key:

Captain Cool posted:

Use long instead of int.

Unsigned Longs and Unions make everything better! This combined with bitWrite got my 32 bit binary counter test working. Time to start working on the CPU/MEM meter.

Warning: 15 mb animated GIF:
https://gifs.com/gif/MjnkV1

It starts with an unsigned long 4,294,967,295 (B11111111111111111111111111111111). 1=led off, 0=led on. There are 8 sections of code similar to this: top bits/bottom bits (evens/odds) * 4. Using bitWrite to manipulate the values based on two random()s.

code:
union u_tag {
    byte b[4];
    long fval;
    } u;
code:
if(j>=8&&j<16){
    bitWrite(u.b[1],j-8,0);
    shiftOut(ds1, cp, LSBFIRST, u.b[0]);
    shiftOut(ds1, cp, LSBFIRST, u.b[1]);
    blank();
    blank();
The next step is to carry over the value from the previous loop, and have the leds step "up" or "down" simulatenously using dual counters and more logic. Once that's ready, it looks pretty simple to build python program to monitor cpu usage and output the values over serial.

Pollyanna
Mar 5, 2005

Milk's on them.


I want to get more into Arduino and embedded development, what are the most recommended starter/project packs out there? Is Adafruit okay, or are there other sources I should get stuff from?

Sagebrush
Feb 26, 2012

Adafruit is great and anything they sell as a starter kit will do the job. Also check out Sparkfun or the official Arduino starter kit. I generally tell my students to stick to Adafruit and Sparkfun for their first couple of projects, because the documentation is really good (especially Adafruit) and there's tons of support for the specific products. With a $2 sensor board from eBay or AliExpress you'll be lucky to get a link to an out-of-date github page with a library.

If you're on a budget, the ~$50 starter kits on Amazon are a good deal and most of the parts will work correctly, but they don't have any learning resources included. Adafruit, Sparkfun and Arduino itself are way better at that.

Sagebrush fucked around with this message at 23:39 on Apr 26, 2017

Pollyanna
Mar 5, 2005

Milk's on them.


Sagebrush posted:

Adafruit is great and anything they sell as a starter kit will do the job. Also check out Sparkfun or the official Arduino starter kit. I generally tell my students to stick to Adafruit and Sparkfun for their first couple of projects, because the documentation is really good (especially Adafruit) and there's tons of support for the specific products. With a $2 sensor board from eBay or AliExpress you'll be lucky to get a link to an out-of-date github page with a library.

If you're on a budget, the ~$50 starter kits on Amazon are a good deal and most of the parts will work correctly, but they don't have any learning resources included. Adafruit, Sparkfun and Arduino itself are way better at that.

Hmm, I might grab one, then. I have an old MEGA 2560 and an Uno from way back when I first got one, but never got the chance to dive in. I'm gonna guess I should move to newer hardware? A starter pack wouldn't be a bad idea in that case.

What do people do for development on an Arduino? I have an MBP and I remember using the Arduino IDE from the website. Is that okay, or are there better tools?

Pollyanna fucked around with this message at 15:21 on May 1, 2017

wolrah
May 8, 2006
what?

Pollyanna posted:

Hmm, I might grab one, then. I have an old MEGA 2560 and an Uno from way back when I first got one, but never got the chance to dive in. I'm gonna guess I should move to newer hardware? A starter pack wouldn't be a bad idea in that case.

What do people do for development on an Arduino? I have an MBP and I remember using the Arduino IDE from the website. Is that okay, or are there better tools?

The Uno R3 is still pretty much the "standard" Arduino and the Mega 2560 is basically a bigger version of the same, so you're fine hardware-wise. There are a lot of Arduino-compatible boards which are more popular in certain niches like Teensy or ESP8266 variants, but if something claims to be "for Arduino" odds are it's built for an Uno or Mega.

The Arduino IDE is also pretty much the standard. It runs on every major platform and is what the "compatible" board vendors will be delivering their addons for. I'm sure you can use any C IDE but you'll have to figure out how to connect the toolchain yourself.

wolrah fucked around with this message at 16:57 on May 1, 2017

Sagebrush
Feb 26, 2012

The Arduino IDE is just fine and works great. If you want something more advanced, you can use Visual Studio with the visual micro plug-in, or atmel studio, both of which are free, but they're pretty bloated for a beginner to figure out and don't offer anything that would be really useful to a learner anyway.

Data Graham
Dec 28, 2009

📈📊🍪😋



Arduino IDE has come on by such leaps and bounds since I started using it, I'm sticking with it purely out of solidarity.

Ever since they added auto library / board management all my gripes are gone.

Splode
Jun 18, 2013

put some clothes on you little freak
PlatformIO is nice of you start writing stuff for arduino longer than a few pages. I used it for a work project and highly recommend it.

The Arduino IDE is usually good enough but it's missing a few quality of life features that you get with serious ides

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
Ran across this whitepaper from Atmel the other day when I was trying to figure out how to make the readings from an analog sensor more accurate -- the paper describes an oversampling method to boost the effective resolution of the ADC at the cost of total processing time. Really helpful method, though obviously since you require exponentially more samples as you push further and further it can slow everything down.
http://www.atmel.com/Images/doc8003.pdf

Pushing the oversampling method to 4 more bits on an Uno takes a while, especially since I'm also doing some averaging of multiple measurements, using a float final output, and also running a GPS chip but it was a massive, massive difference in quality and stability. Sometime I've got to try it on my Due since the built in ADC is 12 bit instead of 10 like the Uno.

On that general ADC/analog sensor stuff, has anyone tried messing with high/low range switches on AREF? I already tied it to 3.3v since that's what the sensor uses and won't put out any more voltage than at theoretical max, but at the same time the manufacturer's recommended range tops out about 3.12v so I'm thinking for a High I could stick a schottky diode to drop it to 3.15-ish instead of discarding the extra range and for Low I could throttle it even more with just plain rear end diodes so it won't try to measure with the higher voltage when the actual output won't hit say even half of that. Seems like something you could do easily with a single throw double pole switch and a few extra lines of code to kick on a warning LED if you've pegged it by accident.

Sagebrush
Feb 26, 2012

I saw that method before and like isn't it literally just time-domain oversampling? Old old old trick. Like it's neat and all but when I was reading that I was like "okay, but get to the clever bit" and it didn't happen.

Like if you do one reading and you get a 668, that's your reading. But if you do 5 readings and get 668,668,664,667,669 and you can assume (1) the signal is constant and (2) the noise is normally distributed around the mean, then you can fairly reliably say that your input reading is 667.2.

They even say that it doesn't work unless the source has some noise, which is exactly what you'd expect with that method.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
I wouldn't be surprised that it's an old trick, but I'm still relatively new to all of this stuff so it was a huge help. :shobon:

Sagebrush
Feb 26, 2012

fake edit: ha, whoops, I thought I was posting in the general electronics thread and not the Arduino thread.

It's a good technique for sure and certainly qualifies as a clever trick if you're new to programming and electronics. Filtering signals can be extraordinarily complicated.

re. your question about adjusting the AREF pin voltage to scale the ADC range -- I'd probably just ignore the difference between 3.3 and 3.15v and make up the difference with code calibration. It's useful to shift the range in broad strokes but any sensor is going to have at least a few millivolts of noise, and no analog device is ever going to behave exactly like another one, and so on. If the extra 50 steps at the top end that you get by using a diode are critical to proper operation of whatever you're building, you're likely to run into problems caused by normal analog behavior regardless of where you set the peak. In that case I'd probably just get a 16-bit SPI ADC (like a dollar on Digi-Key) and have 65 times more resolution than I needed and forget about it.

Parts Kit
Jun 9, 2006

durr
i have a hole in my head
durr
Rad. Definitely was thinking about getting some individual ADCs anyways.

dirksteadfast
Oct 10, 2010
Just a quick question. The wife wanted our new baby stroller to be distinctive, so I'm looking to add EL wire for the frame and a rotating LED POV display for the wheels. Adafruit seems to have a kit that'll work for the latter, but I've never soldered anything or built a board like this before. Is this reasonable for a first time project or am I going to be in over my head pretty quickly?

wolrah
May 8, 2006
what?
Doesn't POV require some pretty decent wheel RPM to actually work? How often is a stroller going to achieve that sort of speed?

That said EL wire is dead simple so assuming you're using a kit for the POV stuff this is entirely reasonable as a first project.

dirksteadfast
Oct 10, 2010

wolrah posted:

Doesn't POV require some pretty decent wheel RPM to actually work? How often is a stroller going to achieve that sort of speed?

I figured if the RPM is insufficient to get a consistent image I can still program in some designs to utilize the motion.

Sagebrush
Feb 26, 2012

dirksteadfast posted:

Just a quick question. The wife wanted our new baby stroller to be distinctive, so I'm looking to add EL wire for the frame and a rotating LED POV display for the wheels. Adafruit seems to have a kit that'll work for the latter, but I've never soldered anything or built a board like this before. Is this reasonable for a first time project or am I going to be in over my head pretty quickly?

EL wire uses a high-frequency inverter that makes an audible whistling noise that I am sure a young child would be able to hear, so maybe don't go that way. Get NeoPixel LED strips instead.

e: and yeah with a single POV strip on a 700c bicycle wheel (622mm diameter) you need to be going like 20mph for total persistence. Smaller wheels will mean you can go slower but you're still gonna be running

Sagebrush fucked around with this message at 18:51 on Jun 14, 2017

JawnV6
Jul 4, 2004

So hot ...
Also, have you seen EL wire in daylight?

dirksteadfast
Oct 10, 2010
Thanks for the input from all. I hadn't ordered anything yet and will consider the new recommendations.

evil_bunnY
Apr 2, 2003

Mosdef get weatherproof neopixel tape. The adafruit learning thingimajig has good sample code to make it do cool/psychedelic stuff.

Hadlock
Nov 9, 2004

JawnV6 posted:

Also, have you seen EL wire in daylight?

Yeah definitely use those LED strips, EL wire looks wicked cool from dusk to dawn, but is invisible during daylight. Also, that whine is pretty audible as long as you're within 15' of a wall, and irritating indoors.

wolrah
May 8, 2006
what?
Anyone have experience with ESP8266 reliability in a long-term application? I want to DIY some home automation sensors and device controllers as a learning experience, but I don't want to have to fiddle with the things regularly once I get them working how I want. There seems to have been a lot of talk questioning their reliability a year or so ago and then it seems to have tapered off, so I'm not sure what to think.

None of it will be for any critical roles, just things like additional temperature sensors and control of the garage door opener, but want to be able to be confident that any failures I experience are my own fault and not the hardware.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

wolrah posted:

Anyone have experience with ESP8266 reliability in a long-term application? I want to DIY some home automation sensors and device controllers as a learning experience, but I don't want to have to fiddle with the things regularly once I get them working how I want. There seems to have been a lot of talk questioning their reliability a year or so ago and then it seems to have tapered off, so I'm not sure what to think.

None of it will be for any critical roles, just things like additional temperature sensors and control of the garage door opener, but want to be able to be confident that any failures I experience are my own fault and not the hardware.

It depends what you mean by reliability. Is a shutdown and recovery lasting 15 minutes every 10 hours still reliable because it has 0 consequences?

Anyway here's a thing that shows there's a fair amount of fiddling for your application and the longest ever period without a reset was less than 2 months.There's a link at the bottom of the article to the ThingSpeak page that has the data: https://internetofhomethings.com/homethings/?tag=esp8266-stability

Sagebrush
Feb 26, 2012

Assuming the hardware itself doesn't crap out, and you haven't inadvertently done something dumb like code in an unhandled overflow, microcontrollers are usually extremely reliable. I wouldn't put a homemade ESP8266 IoT device on my thermostat or oven or whatever just on principle, but I'd be perfectly confident attaching one to a lamp.

The previous poster's point is also good. Even if the system does get crapped up somehow, is it acceptable to have it automatically reset every day for a few seconds at 3am?

e: I read the link posted above and the guy says that his ESP8266 was crashing all the time -- but also that he was polling for HTTP requests on every loop (not a good idea) and that his USB to serial converter was browning out. So poor code practice and a broken external component. He fixed those two things and the chip runs perfectly. Ergo: yes, it's totally possible if you do it right.

Sagebrush fucked around with this message at 17:50 on Jul 1, 2017

Sebbe
Feb 29, 2004

wolrah posted:

Anyone have experience with ESP8266 reliability in a long-term application? I want to DIY some home automation sensors and device controllers as a learning experience, but I don't want to have to fiddle with the things regularly once I get them working how I want. There seems to have been a lot of talk questioning their reliability a year or so ago and then it seems to have tapered off, so I'm not sure what to think.

None of it will be for any critical roles, just things like additional temperature sensors and control of the garage door opener, but want to be able to be confident that any failures I experience are my own fault and not the hardware.

I've had a ESP8266 running with a temperature sensor for at least a year, and I haven't had to tend to it even once.

I've configured it to just start over whenever anything fails - so if there's wifi outage, power outage, whatever, it just starts working whenever it resolves itself.

(This reminded me that I actually need to update it with my new wifi credentials; changed them a few days ago.)

wolrah
May 8, 2006
what?

CarForumPoster posted:

It depends what you mean by reliability. Is a shutdown and recovery lasting 15 minutes every 10 hours still reliable because it has 0 consequences?

If it takes 15 minutes to recover that might be annoying for certain things like the garage door opener, but yeah reboots are no big deal for the kinds of things I'm picturing.

Sagebrush
Feb 26, 2012

Something like an ESP8266 takes like 15 seconds to recover, if that, and most of that time is reconnecting to the wireless. "Boot" time is effectively zero.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Sagebrush posted:

Something like an ESP8266 takes like 15 seconds to recover, if that, and most of that time is reconnecting to the wireless. "Boot" time is effectively zero.

This.

I was making a point about reliability being baked in to your error handling/software/use case rather than being worried about "reliable" hardware. I haven't used an ESP8266 but my Arduinos resume on crash/power failure in something like 30 seconds or less.

EDIT:
When you can properly recover from failures in the micro controller world you're now only worried about "hard"/permanent failures which are much less frequent. You still have to prepare for them and make sure whatever is receiving this data handles soft and hard failures without causing major issues.

You wouldnt want your A/C to stay permanently on because your ESP8266 outputs a stream of 82°F even though the temp is really 70°F.

CarForumPoster fucked around with this message at 05:03 on Jul 4, 2017

Adbot
ADBOT LOVES YOU

Harvey Baldman
Jan 11, 2011

ATTORNEY AT LAW
Justice is bald, like an eagle, or Lady Liberty's docket.

I am crossposting this to the electronics megathread because it's an overlapping subject.

I've never worked with motors. My arduino knowledge has mostly been lights/sound.

I'm working on the ZF-1 gun from the Fifth Element.



https://www.youtube.com/watch?v=7jVsQToSfag

There are a few hatches and things that I'd like to engineer into actually opening or extending, controllable via arduino. First impulse was to look up "linear actuator", only to discover that that poo poo is expensive, probably because most of them are load bearing.

What's the cheapest way to do something like extend a barrel here? Something with a regular motor and a rail with teeth?



Is there an easier answer I'm missing?

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