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
ephphatha
Dec 18, 2009




I've got a digispark pro (ATtiny167 based device) and I'm trying to read temp/humidity data from an AM2320. I can't get a proper read from it. The datasheet says the response should be a sequence of bytes confirming the instruction, the datagram length, the requested data, then a two byte CRC. What I'm actually getting back is the instruction confirmation, a zero byte, the expected length, then 0 bytes for the rest of the data.

I've got it hooked up to 5v and to the SDA/SCL pins on the pro (with 4.7k pullups) and the basic code I'm using is as follows:

code:
#include <Wire.h> //Actually refers to TinyWireM.h

#define AM2320_ADDRESS (0xB8 >> 1)
#define AM2320_READREG 0x03

void setup() {
  Wire.begin();
}

void loop() {
  //wake up the sensor
  Wire.beginTransmission(AM2320_ADDRESS);
  delay(1); //Need to wait 800us to 3ms before sending endTransmission.
  uint8_t retVal = Wire.endTransmission();

  //retVal is 0x01, no ACK on address  

  delay(2); //No wait necessary before triggering read?

  //tell the sensor we want the current readings
  Wire.beginTransmission(AM2320_ADDRESS);
  Wire.write(AM2320_READREG); //Read sensor data
  Wire.write(0x00); //Start from the first register
  Wire.write(4); //Read all registers (2 bytes per sensor, 2 sensors)
  retVal = Wire.endTransmission();

  //retVal is usually 0x01, no ACK on address - occasionally 0x02, no ACK on data on the first iteration

  delay(10); //Need to wait at least 1.5ms before requesting data.

  retVal = Wire.requestFrom(AM2320_ADDRESS, 8);

  //retVal is again 0x01, no ACK on address

  union {
    byte buffer[8];
    struct {
      byte instruction;
      byte length;
      unsigned short humidity;
      short temp;
      unsigned short crc;
    } data;
  } sensor;

  for (uint8_t i = 0; i < 8; ++i) {
    if (retVal = Wire.available()) {
      sensor.buffer[i] = Wire.read();
      //retVal counts down from 8 as expected.
      //sensor.buffer fills with 03:00:04:00:00:00:00:00, expected 03:04:hh:hl:th:tl:ch:cl
    } else {
      break;
    }
  }

  delay(2000);
}
I hadn't been checking the return codes of most of the wire calls when first testing since it seems to recognise the command and at least start to build a proper response, so I'm not sure if the no-acks are something I should be concerned about. I'm also getting a consistent response, the exact same sequence of bytes and (99.9% of the time) the same error codes for the endTransmission/requestFrom calls every time it executes.

As far as I can tell the timings in the USI_TWI_Master files are exactly what the sensor expects but I'm not confident enough to try change any of those values. I've also seen other code samples for this sensor put a delay between reads but with the tinywire library the requested data is prefetched when requestFrom is called so there's no point.

Any ideas what's loving up and how I can fix it?

Adbot
ADBOT LOVES YOU

Captain Cool
Oct 23, 2004

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

Ephphatha posted:

I hadn't been checking the return codes of most of the wire calls when first testing since it seems to recognise the command and at least start to build a proper response, so I'm not sure if the no-acks are something I should be concerned about. I'm also getting a consistent response, the exact same sequence of bytes and (99.9% of the time) the same error codes for the endTransmission/requestFrom calls every time it executes.
You're not actually talking to the device. The device should ack its address. The response you're getting -- 03 00 04 00 ... -- is the same as the command you sent. I'm guessing the Wire library uses the same buffer for sending and receiving.

huhu
Feb 24, 2006
Does anyone sell kits for all the parts needed to make more permanent Arduino projects?

I believe this is the list of required parts:

Atmega8/16
16MHz crystal
22pf capacitor
10uf capacitor
Resistor 10K , 100K
Jumber wire

ephphatha
Dec 18, 2009




Captain Cool posted:

You're not actually talking to the device. The device should ack its address. The response you're getting -- 03 00 04 00 ... -- is the same as the command you sent. I'm guessing the Wire library uses the same buffer for sending and receiving.

Welp, that seems so obvious in retrospect. Thanks, I'll see if I can get this thing to respond.

Seat Safety Switch
May 27, 2008

MY RELIGION IS THE SMALL BLOCK V8 AND COMMANDMENTS ONE THROUGH TEN ARE NEVER LIFT.

Pillbug

huhu posted:

Does anyone sell kits for all the parts needed to make more permanent Arduino projects?

I believe this is the list of required parts:

Atmega8/16
16MHz crystal
22pf capacitor
10uf capacitor
Resistor 10K , 100K
Jumber wire

I'd just make a mass order on Digikey for however many you plan to make and then re-up the cart as you run out. Their shipping is pretty fast.

You'll probably also want something to handle the 5V power supply and some kind of programmer for the AVRs (I guess you could use Arduino ISP).

Star War Sex Parrot
Oct 2, 2003

huhu posted:

Does anyone sell kits for all the parts needed to make more permanent Arduino projects?

I believe this is the list of required parts:

Atmega8/16
16MHz crystal
22pf capacitor
10uf capacitor
Resistor 10K , 100K
Jumber wire

Seat Safety Switch posted:

I'd just make a mass order on Digikey for however many you plan to make and then re-up the cart as you run out. Their shipping is pretty fast.

You'll probably also want something to handle the 5V power supply and some kind of programmer for the AVRs (I guess you could use Arduino ISP).
The into to embedded class at my university has a similar shopping list they just give DigiKey part numbers for, yeah. I'll see if I can dig it up if it helps at all. Includes everything you need to run it off of a 9V battery, though I eventually picked this guy up for the 5V:

https://www.sparkfun.com/products/114

Skunkduster
Jul 15, 2005




Dad asked me to pass on his thanks. He was able to get his assembly file loaded using objcopy so that is a big roadblock out of the way.

huhu
Feb 24, 2006

Star War Sex Parrot posted:

Neat. Reminds me of the intervalometer I made a year or so ago:



Could set number of shots, time before beginning the sequence, time interval between shots, and exposure time (since camera was in Bulb mode).

How long does this generally last? Is the camera good at going into some sort of a standby mode?

Edit:
Found this for the barebones Arduino: http://www.ebay.com/itm/Bareduino-Bare-minimum-16-MHz-Arduino-Kit-/321280659150?hash=item4acdd1cece:g:XfkAAOxy63FSthRf

huhu fucked around with this message at 18:34 on Mar 15, 2016

Amberskin
Dec 22, 2013

We come in peace! Legit!

huhu posted:

Does anyone sell kits for all the parts needed to make more permanent Arduino projects?

I believe this is the list of required parts:

Atmega8/16
16MHz crystal
22pf capacitor
10uf capacitor
Resistor 10K , 100K
Jumber wire

If you can live with running the MCU and 8MHz instead of 16, and you don't care about timing being super-precise, you don't need the crystal.

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


edit: I think I've seen the problem (of course, just after I post asking for help!). I will never get more than a couple of ms difference between the currentMillis and previousMillis, due to where it updates those values, right?


I mentioned before that I am totally new to all this, so sorry in advance for the stupid newbie question.
I don't really understand why it isn't working, so I thought I'd ask here. I have spent over an hour since I thought the code was passing Verify checks trying to get the LED to flash, in a couple of different ways, so it's not like I gave up at the first hurdle.


After a couple of weeks of reading around on-and-off, I finally got around to installing the IDE and plugging in the arduino!

I thought the best idea would be to start by modifying an example program.

I chose to try to make an asymmetric "BlinkWithoutDelay" (since I don't want to get into the habit of relying on delay - I'm going to need to be scanning a lot of inputs for my final "Ultimate Goal" project).

However, I've hit a bit of a wall. Blink and BlinkWithoutDelay work, so I know it must be me getting something wrong - problem is, I can't see what.

code:
const int ledPin = 13;
int ledState = LOW;
unsigned long previousMillis = 0;
const long intervalOn = 1000;
const long intervalOff = 500;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  unsigned long currentMillis = millis();         //snapshot the current time
  
  if  (((currentMillis - previousMillis) >= intervalOn) && (ledState == HIGH)) {
      ledState = LOW;
    }
  //^If the led is on AND has been on longer than "intervalOn", turn the led off
  
 else if (((currentMillis - previousMillis) >= intervalOff) && (ledState == LOW)) {
    ledState = HIGH;
  } 
  //^Otherwise, if the led is off AND has been off longer than "intervalOff", turn the led on
  
  digitalWrite (ledPin,ledState); //do appropriate output to the led
  previousMillis = currentMillis; // shift the timer along
}
The LED blinks once (could be just as a byproduct of the upload?) and then stays off

Of course, the first bit of troubleshooting I did was to mess around with things and see what changed.

If I set previousMillis at the beginning to 990, on upload the LED starts on and stays on


I also tied rephrasing what I want as something a little closer to the initial example:
code:
void loop() {
  unsigned long currentMillis = millis();         //snapshot the current time
  
  if ( ledState == HIGH ) {
     if ((currentMillis - previousMillis) >= intervalOn) {
      ledState = LOW;
    }
  }
  //^If the led is on AND has been on longer than "intervalOn", turn the led off
  
 else if (ledState == LOW) {
  if ( (currentMillis - previousMillis) >= intervalOff) {
    
    ledState = HIGH;
  } 
 }
  //^Otherwise, if the led is off AND has been off longer than "intervalOff", turn the led on
  
  digitalWrite (ledPin, ledState); //do appropriate output to the led
  previousMillis = currentMillis; // shift the timer along
}
Appreciate any advice/feedback on the problem or just generally.

simplefish fucked around with this message at 20:51 on Mar 16, 2016

Sir Bobert Fishbone
Jan 16, 2006

Beebort
You'd probably want to put your

previousMillis = currentMillis; // shift the timer along

inside the if/then, right?

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


Yeah, I saw it right as I posted it (sod's law), and got it to work:

code:
  if  (((currentMillis - previousMillis) >= intervalOn) && (ledState == HIGH)) {
      ledState = LOW;
      previousMillis = currentMillis; // shift the timer along
    }
Just like you say.

Really impressed how fast you replied, and straight to the point, though - thank you!

Sir Bobert Fishbone
Jan 16, 2006

Beebort

simplefish posted:

Yeah, I saw it right as I posted it (sod's law), and got it to work:

code:
  if  (((currentMillis - previousMillis) >= intervalOn) && (ledState == HIGH)) {
      ledState = LOW;
      previousMillis = currentMillis; // shift the timer along
    }
Just like you say.

Really impressed how fast you replied, and straight to the point, though - thank you!

I've been in your shoes!

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


It works with the alternative phrasing too.

Is one better than the other (boolean vs nesting ifs)? If one's a bad habit, I'd rather not form it at this stage,

huhu
Feb 24, 2006
I'm trying to move my arduino circuit to an Atmega328 powered circuit. I've got an SD card reader that requires 3.3V but everything else needs 5V. How would I wire up the SD card reader?

huhu
Feb 24, 2006
Edit: So after a ton of reading, it looks like I have to connect pin 1 on the Atmega to Reset on the Arduino to upload a sketch. Not sure why this wasn't mentioned in the guide I was reading.

Can't attach image to edits so uploading here with new post...

I purchased an Atmega328P-PU from my makerspace and they burned the atmega328 bootloader to it. I wired everything up and I have a blinking light so I know it works. I select the Arduino/Geunino Uno from the dropdown menu as the board and try to upload any sketch and get:
code:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x24
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x24
Problem uploading to board.  See [url]http://www.arduino.cc/en/Guide/Troubleshooting#upload[/url] for suggestions.
I've got an image below. I've tried changing USB ports, putting my other Atmega chip back on the board and it works. What am I missing?

Only registered members can see post attachments!

huhu fucked around with this message at 00:36 on Mar 17, 2016

Sagebrush
Feb 26, 2012

simplefish posted:

Is one better than the other (boolean vs nesting ifs)? If one's a bad habit, I'd rather not form it at this stage,

When you say boolean, do you mean &&, the logical AND? I don't think there's a functional difference between that and the conditional if/else statement, in terms of execution time or whatever. Using the conditional gives you the option of multiple paths of execution though:

code:
if (a && b) {
  //do something when both true
}
else {
  //do something for !a && b, a && !b, or !a && !b
}
code:
if (a) {
  if (b) {
    //case for both true
  }
  else {
    //a && !b
  }
}
else {
  if (b) {
    //!a && b
  }
  else {
    !a && !b
  }
}
  
Kinda gross to look at IMO but definitely more powerful.


huhu posted:

I'm trying to move my arduino circuit to an Atmega328 powered circuit. I've got an SD card reader that requires 3.3V but everything else needs 5V. How would I wire up the SD card reader?

Get thee to a level shifter. SD cards are low enough current that you could probably get away with a pair of resistors in a voltage divider.

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
I'm building a kind of self-calibrating stepper-motor controller thingie, and I can already feel I'm going to need an event and timer system, which goes beyond the basic low-level timer libraries. Is there any one good "framework" which provides good implementations of these kinds of things?

I've found 3 or 4 different libs that have varying levels of quality. This just feels like basic stuff that a smart group of people might have done before. Any ideas?

Spazzle
Jul 5, 2003

v1nce posted:

I'm building a kind of self-calibrating stepper-motor controller thingie, and I can already feel I'm going to need an event and timer system, which goes beyond the basic low-level timer libraries. Is there any one good "framework" which provides good implementations of these kinds of things?

I've found 3 or 4 different libs that have varying levels of quality. This just feels like basic stuff that a smart group of people might have done before. Any ideas?

I've maybe been doing something similar using accelstepper. Does this help?
code:
 
#include <AccelStepper.h>

AccelStepper s1(1,22,23);
AccelStepper s2(1,24,25);
AccelStepper s3(1,26,27);
AccelStepper s4(1,28,29);
AccelStepper s5(1,30,31);
AccelStepper s6(1,32,33);
AccelStepper s7(1,34,35);
AccelStepper s8(1,36,37);
AccelStepper steppers[]={s1,s2,s3,s4,s5,s6,s7,s8};
int endstops[]={52,53,44,45,46,47,48,49};
int numaxes =4;
int channel=0;
int route;
long routevalue;
long count=1;
long lastt=0;
long dist;

void setup() {
Serial.begin(115200);
  for (int x=0; x< numaxes;x++){
  steppers[x].setMaxSpeed(500);
  steppers[x].setAcceleration(100);
  pinMode(endstops[x],INPUT);
  }
}

void loop() {
  parseinputcomplex();
  movesteppers();
  framerate();
}

void movesteppers(){
    for (int x=0; x< numaxes ;x++){
    dist=steppers[x].distanceToGo();
    if(dist<0&&digitalRead(endstops[x])==1){
      steppers[x].setCurrentPosition(0);
      steppers[x].moveTo(0);
    }
    if (dist!=0){
    steppers[x].run();
    }
  }
}

void parseinput(){// targets an axis to a set location. Syntax is
[channel value]. Can stack multiple commands.
    while (Serial.available() > 0) {
    channel = Serial.parseInt();
    routevalue = Serial.parseInt();
    steppers[channel].moveTo(routevalue);
    Serial.print(channel);
    Serial.print(" ");
    if (Serial.read() == '\n') {
      Serial.println("go");
    }
  }
}

void parseinputcomplex(){// allows for a broader range of commands
than parseinput. Syntax is [channel command value] ie [0 1 200].
Commands can stack.
    while (Serial.available() > 0) {
    channel = Serial.parseInt();
    route= Serial.parseInt();
    routevalue = Serial.parseInt();

    if (route==0){//Set target position
    steppers[channel].moveTo(routevalue);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(" Target Position ");
    Serial.println(routevalue);
    }

    if (route==1){//move by
    steppers[channel].moveTo(routevalue+steppers[channel].targetPosition());
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(" Move By ");
    Serial.println(routevalue);
    }

    if (route==2){//set max speed
    steppers[channel].setMaxSpeed(routevalue);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(" Max speed ");
    Serial.println(routevalue);
    }

    if (route==3){//set  accelleration
    steppers[channel].setAcceleration(routevalue);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(" Accelleration ");
    Serial.println(routevalue);
    }

    if (route==4){//set current location
    steppers[channel].setCurrentPosition(routevalue);
    Serial.print("Channel ");
    Serial.print(channel);
    Serial.print(" Current position set to ");
    Serial.println(routevalue);
    }

    if (route==5){//report status. Channel and value not used. Use
dummy value (such as 0). All distance units in steps.
      for(int n=0;n<numaxes;n++){
      Serial.print("Chn ");
      Serial.print(n);
      Serial.print(" Targ. Pos ");
      Serial.print(steppers[n].targetPosition());
      Serial.print(", Cur. Pos ");
      Serial.print(steppers[n].currentPosition());
      Serial.print(", Current Spd ");
      Serial.print(steppers[n].speed());
      Serial.print(", Current Max Spd ");
      Serial.println(steppers[n].maxSpeed());
      }
    }

    if (Serial.read() == '\n') {
      Serial.println("go");
    }
  }
}

void framerate(){
    if(count%50000==0){
    Serial.print(1000*count/(millis()-lastt));
    Serial.println(" Cycles per second");
    lastt=millis();
    count=0;
  }
   count=count+1;
}

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.
That's a bit more specific than what I was going for. I was more interested to see if there's any group of libraries out there with general implementations of event and timer stacks.

To be more specific about what I'm doing: I'll have several pieces of hardware attached to a single Teensy.
Each item needs to perform calibration operations, which written at their most basic, use delay() and block the main thread.

The calibration really doesn't need to happen one-by-one. I can rewrite these methods to be event/timer based and non-blocking, but I was paralysed by the choice of so many disparate libraries.

Is there any one main-effort general-purpose community library for these general purpose things, or am I just best off going for "whatever works"?

Edit: the hardware is only analogous to a stepper motor; it isn't actually one. I've already got that part sorted, but I want to un-block the main thread during calibration.

v1nce fucked around with this message at 06:02 on Mar 22, 2016

huhu
Feb 24, 2006
Are there any good video series that go through various important components in Arduino projects? Right now I'm looking at videos for 555 timers and stepper motors and am wondering if there are a series that introduces various components?

porksmash
Sep 30, 2008
I'm not sure about videos, but https://learn.adafruit.com/ has a huge amount of guides and tutorials from components to projects.

politicorific
Sep 15, 2007
Is there anyway to multiplex a 4x4 keypad using a 165 or 4021? Or any other IC or protocol?

Throw in a 1602 LCD and I'm practically out of pins on my nanos. I have read I can use resistors in conjunction with an analog switch or gently caress around with a 595+165 but I'd prefer simple over complex.

SPI? ic2?

huhu
Feb 24, 2006
Any suggestions for a robotics kit that isn't just a "buy this preassembled thing, load the code and run it"? I'm looking for a package that might have parts to make basic linear/rotational movement, wheels, motors, etc.

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


politicorific posted:

Is there anyway to multiplex a 4x4 keypad using a 165 or 4021? Or any other IC or protocol?

Throw in a 1602 LCD and I'm practically out of pins on my nanos. I have read I can use resistors in conjunction with an analog switch or gently caress around with a 595+165 but I'd prefer simple over complex.

SPI? ic2?

Would this help?
https://m.youtube.com/watch?v=nXl4fb_LbcI

Same guy has several other videos on shift registers, I found them informative

E: He addresses the using analogue inputs with different resistors in another video (or maybe this one? I can't remember and I can't watch where I am right now), and brings up the point of what happens when two buttons are pressed at the same time (you get a voltage your program isn't expecting)

simplefish fucked around with this message at 20:27 on Mar 29, 2016

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


Sorry for the double post, but I'm quoting on mobile


Sagebrush posted:

Look at how numerical keypads are traditionally read, and the code used to do that. Adafruit has a nice tutorial: https://www.adafruit.com/products/419

This was a helpful suggestion when I asked something similar a few weeks back

Skunkduster
Jul 15, 2005




I'm designing a thing for work that will be 10 test stations that will each be used to test battery life. All 10 stations will be identical. My concern is how to mount all of the electronics and make it look decent. Each test station will have an Arduino Uno, 16x2 LCD, prototype board, and a couple buttons and LEDs. There are other components (power supply, load, battery dock) that will be external to the housing and I already have that figured out. Any suggestions on some type of large project box that is wall mountable that can hold all this stuff and be machinable so I can mount the LCDs? I have the tools to machine plastic and could probably do aluminum or steel if I had to, but plastic would be best. It will be located in the service area at my work, so it doesn't have to look amazing, but I'd like it to be a little more professional looking than a bunch of poo poo screwed to a piece of plywood.

edit: One box would be preferred, but not critical - 2 boxes with 5 units each, or 10 individual boxes would also work if I had a way to mount them to the wall.

Skunkduster fucked around with this message at 23:30 on Apr 1, 2016

Sagebrush
Feb 26, 2012

What tools do you have access to?

If you can make straight cuts on plastic pieces, you could make your own box out of acrylic panels by cementing them together at the corners. Try something like this:

http://makezine.com/projects/tape-hinge-acrylic-box-construction/

You can get acrylic in a wide range of colors and thicknesses, so you can get the effect you want. You can also drill holes for buttons, etc. and panel-mount them. Look up some tutorials if you're going to do this, as acrylic is brittle and can split, but it's a well established strategy for low-run things like this.

Rexxed
May 1, 2010

Dis is amazing!
I gotta try dis!

SkunkDuster posted:

I'm designing a thing for work that will be 10 test stations that will each be used to test battery life. All 10 stations will be identical. My concern is how to mount all of the electronics and make it look decent. Each test station will have an Arduino Uno, 16x2 LCD, prototype board, and a couple buttons and LEDs. There are other components (power supply, load, battery dock) that will be external to the housing and I already have that figured out. Any suggestions on some type of large project box that is wall mountable that can hold all this stuff and be machinable so I can mount the LCDs? I have the tools to machine plastic and could probably do aluminum or steel if I had to, but plastic would be best. It will be located in the service area at my work, so it doesn't have to look amazing, but I'd like it to be a little more professional looking than a bunch of poo poo screwed to a piece of plywood.

edit: One box would be preferred, but not critical - 2 boxes with 5 units each, or 10 individual boxes would also work if I had a way to mount them to the wall.

Like Sagebrush said you can build your own or there's a lot of project boxes available online. They're not as cheap as you'd think but I've bought some Hammond ones from amazon that were pretty easy to cut and drill into to make spots for keypads/LEDs/switches. I mostly used a drill, coping saw and files. The main thing is to get an idea of the layout of the insides and measure them for an enclosure. Putting them in the enclosure you can use almost anything but someone with more experience may have better suggestions than I do. Nylon standoffs are what I've mostly used with a little hot glue, but don't overdo it. I've also cut up some old cd jewel cases for random bits of mounting plasti. If you leave enough space you can screw them to the wall from inside the box, or you can buy some with ears and mounting holes. It's not too hard to make it look nice as long as you don't gently caress up the surface of the box and label the switches and lights.

Fanged Lawn Wormy
Jan 4, 2008

SQUEAK! SQUEAK! SQUEAK!
I'm a big fan of the CMB boxes by Bud Industries, I use them a lot for one-off controllers at work:


http://www.budind.com/view/NEMA+Boxes/NEMA+4X+With+Mounting+Brackets

External mounting tabs are nice, and I'm a big dork for clear lids.

I'd be happy to hear other tool suggestions like Rexxed gave, but I use a diamond cutting blade on a dremel tool when I can. Another good strategy for rectangles is to drill a series of perforations to make an outline which is much easier to cut. The trick with ABS is to try and avoid too much friction/heat.

I like the suggestion of acrylic enclosures too - something like what Phidgets uses:

It's a laser-cut flat pack pattern that slots together. You could then use fluid to bond it together where desired. You'd need to design it yourself though, and find somebody to cut it I bet, so that might not be economical. I just saw them recently and thought they were really clever :3:

huhu
Feb 24, 2006
I have a few questions:

1. I replaced the potentiometer with a resistor on my LCD screen and it worked fine until I tried different power sources - 3V from 2AA and 6V from a wall wart. I'm guessing the difference in voltage as compared to the arduino's 5V is causing the issue? If so am I going to have to use the potentiometer if I plan to switch between power sources?

2. I've run out of memory using my arduino with libraries for an SD card read, LCD screen, and Arducam camera. How easy/hard would it be to go in and start removing chunks of code to safe some space?

3. My arduino camera I designed sometimes randomly fails/resets itself after taking several hundred pictures. What would be the best method to troubleshoot something that happens randomly minutes/hours running? My first thought is to create a text file that records all the inputs I sent to the camera (# of pictures, duration to shoot) and record each time a picture is taken, the current time, and then eventually it'll fail and that'll be the end of my text file.

huhu fucked around with this message at 16:38 on Apr 5, 2016

simplefish
Mar 28, 2011

So long, and thanks for all the fish gallbladdΣrs!


Why not go 4AA for 6V, then try to make 6V work?

Captain Cool
Oct 23, 2004

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

huhu posted:

1. I replaced the potentiometer with a resistor on my LCD screen and it worked fine until I tried different power sources - 3V from 2AA and 6V from a wall wart. I'm guessing the difference in voltage as compared to the arduino's 5V is causing the issue? If so am I going to have to use the potentiometer if I plan to switch between power sources?
How did you replace the pot? If you want to simulate a certain fixed position you might need two resistors.

quote:

2. I've run out of memory using my arduino with libraries for an SD card read, LCD screen, and Arducam camera. How easy/hard would it be to go in and start removing chunks of code to safe some space?
It's not hard to look. If you can scale things back just enough to get it to compile, find the map file and see what is taking up so much room. Turn on verbose compile output and make sure you're compiling with -Os.

quote:

3. My arduino camera I designed sometimes randomly fails/resets itself after taking several hundred pictures. What would be the best method to troubleshoot something that happens randomly minutes/hours running? My first thought is to create a text file that records all the inputs I sent to the camera (# of pictures, duration to shoot) and record each time a picture is taken, the current time, and then eventually it'll fail and that'll be the end of my text file.
Serial logging might be simpler to watch, but it will require more memory. You could try a debugger and see if you can break in on the failure. If you have your code wait for a button press or serial input before entering the main loop, you can catch it right after it resets, if that's useful.

JawnV6
Jul 4, 2004

So hot ...

huhu posted:

3. My arduino camera I designed sometimes randomly fails/resets itself after taking several hundred pictures. What would be the best method to troubleshoot something that happens randomly minutes/hours running? My first thought is to create a text file that records all the inputs I sent to the camera (# of pictures, duration to shoot) and record each time a picture is taken, the current time, and then eventually it'll fail and that'll be the end of my text file.
So your api calls succeed, but you check where the file should be and it's not there or corrupted? Your setup is the proper first step, but as long as you're setting that up you should be thinking about the solution space in parallel. I find that distinction incredibly helpful, before you run any experiment it's good to ask if you're running it for a question about the problem space (e.g. 'what's happening right before failure?') or solution space ('if this code is implemented,

A few approaches to consider:
1) Reboot the camera for every picture. If your duty cycle is low enough and the init doesn't draw exceptional power, just resetting the peripheral to a know good state every time might work. I'd be curious if that actually solves it or if there's some other marginal condition that's
2) Poll registers. Print out every value you can get to on every iteration. Use the setup you describe to detect when the camera goes bad and look for something that correlates with that moment. Then you'd code a loop that checked for Register X to have Value Y (i.e. chipID = 0xffff) and reboot the part when that condition is detected.
3) Time it out. See how long a 'good' picture takes. See how long the failing one takes. If there's a consistent enough difference, use that to determine when to reboot the peripheral.
4) LA. Watch transactions, figure out a way to trigger on the bad one, see what's happening at that level when things go off the rails. Building off Captain Cool's suggestion, trigger on a reset at the 99% mark should capture failing traffic.

So 1 is a mix between problem/solution, 2 and 3 are both solution space, 4 is pure problem space.

Skunkduster
Jul 15, 2005




Rexxed posted:

Like Sagebrush said you can build your own or there's a lot of project boxes available online. They're not as cheap as you'd think but I've bought some Hammond ones from amazon that were pretty easy to cut and drill into to make spots for keypads/LEDs/switches. I mostly used a drill, coping saw and files. The main thing is to get an idea of the layout of the insides and measure them for an enclosure. Putting them in the enclosure you can use almost anything but someone with more experience may have better suggestions than I do. Nylon standoffs are what I've mostly used with a little hot glue, but don't overdo it. I've also cut up some old cd jewel cases for random bits of mounting plasti. If you leave enough space you can screw them to the wall from inside the box, or you can buy some with ears and mounting holes. It's not too hard to make it look nice as long as you don't gently caress up the surface of the box and label the switches and lights.

I was looking at the boxes from Hammond and couldn't find anything large enough. Even though I do have the tools to cut and build with acrylic, I'm not too keen on doing that because this is something for work and I'd rather just have the company buy a finished box - I'm paid salary, so if I built it at home, it would be outside my work hours and I wouldn't be getting paid for it. I was sitting at my desk today thinking about it and spotted the fire extinguisher cabinet mounted on the wall and found my answer :)

Skunkduster
Jul 15, 2005




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.

Skunkduster fucked around with this message at 04:23 on Apr 8, 2016

huhu
Feb 24, 2006

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. One reason is that declaring variables outside of setup() or loop() causes them to become global variables. If you don't know what global variables are I'd read up on global vs local variables.

2. You can setup something like this to keep time: https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard

3. What is your reasoning for this?

4. Little confused by your question, but you could do:
code:
void A(){stuff}
void B(){stuff}
void C()stuff}

void setup(){stuff}
void loop(){
    if(something == HIGH){A();}
    if(something == HIGH){B();}
    if(something == HIGH){C();}
}
or something like this might be what you're asking for...
code:
currentFunction = "A";
if(currentFunction == "A" && button1 == "HIGH"){
    currentFuncton == "B";
    B();
}

huhu fucked around with this message at 05:02 on Apr 8, 2016

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.
      ;
   }

Skunkduster
Jul 15, 2005




huhu posted:

1. One reason is that declaring variables outside of setup() or loop() causes them to become global variables. If you don't know what global variables are I'd read up on global vs local variables.

2. You can setup something like this to keep time: https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard

3. What is your reasoning for this?

4. Little confused by your question, but you could do:
code:
void A(){stuff}
void B(){stuff}
void C()stuff}

void setup(){stuff}
void loop(){
    if(something == HIGH){A();}
    if(something == HIGH){B();}
    if(something == HIGH){C();}
}
or something like this might be what you're asking for...
code:
currentFunction = "A";
if(currentFunction == "A" && button1 == "HIGH"){
    currentFuncton == "B";
    B();
}

1. I don't know what global variables are, but now that I know what they are called, I can learn about them.

2. Thanks. I'm going to have to look into this. It would make the project cleaner if I could use one prototype board for all the components instead of a bunch of jumper wires from the Arduino over to the prototype board.

3. It seemed to make more sense to me that if I was using the chip as a standalone to write the code for the pins of the chip instead of the breakouts on the Arduino that wouldn't be part of the circuit. I'm very new to this, so maybe I am misunderstanding some basic concepts.

4. The second example should get me on the right track. The code will go through 5 stages. Depending on what stage it is in, I need button 1 to do different things. I don't know the syntax well enough to write from scratch so I rely on finding examples and modifying them, but this is the logical concept of what I am after:

code:
Function A:
Do some stuff
If button A is pressed, go to function B
else do function A.
Am I right to assume that this can be done and will just loop function A over and over and ignore the rest of the void loop? I can figure out the syntax later, I just want to know if that is the right way to approach the problem.

Adbot
ADBOT LOVES YOU

Star War Sex Parrot
Oct 2, 2003

SkunkDuster posted:

4. The second example should get me on the right track. The code will go through 5 stages. Depending on what stage it is in, I need button 1 to do different things. I don't know the syntax well enough to write from scratch so I rely on finding examples and modifying them, but this is the logical concept of what I am after:
Look up some tutorials on finite state machines and implementation methods for C.

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