Hi all, I'm pulling my hair out tonight (or at least what's left of it). I'm working on a project that involves multiple breadboarded Digisparks. I was having a hard time making sense of why outputs were or weren't being activated when they should be, so I simplified it by working with one at a time now. For at least 2 of the 8 sparks ( I haven't tested the other 6 yet), I seem to be having a problem with my VIN. When I power the spark over USB, the sketch runs fine, and pin 0 outputs as it should. I've tested it with an LED and my multimeter, and I get 4.70 volts. When I power it with a 12V NiMH 2.1A battery (which is outputting 12.9V per the multimeter) hooked up to the VIN pin, and the ground from the battery to the ground pin, the multimeter is telling me that I'm getting no output from pin 0. One interesting thing is that the green power LED does come on when VIN power is applied (to both of the 2 I tested), but the sketch doesn't appear to be running. The sketch is definitely uploaded to the spark, because I test this serially, first with USB power but not transferring the sketch again, and then with VIN power. I will go through and test the others (I bought 10 total), but I just wanted to check in and make sure I'm not doing something wrong here. The sketch is pasted below, I've commented out some things during testing but the important code is at the bottom showing pin 0 and pin 1 turned to HIGH. Thoughts?
TIA,
Joe
//Inhibitory Endogenous Burster
//Cell A or B
#include "DigiKeyboard.h"
int cell1 = 1; //digital pin 2
int cell1Raw = 0;
int cell1Scaled = 0;
int avgScaled = 0;
int internalState; //value output to the PWM (analog out)
float sinVal;
const int taOut = 0;
const int ebOut = 1;
int outputLevel;
int IPSP = 0; //IPSP gives synaptic weight of 0
int noInput = 50;
void setup(){
//P0, P1, and P4 are capable of hardware PWM (analogWrite).
//pinMode(0, OUTPUT); //0 is P0, 1 is P1, 4 is P4 - unlike the analog inputs,
//for analog (PWM) outputs the pin number matches the port number.
pinMode(taOut,OUTPUT); //digital pin 0; to tonically active A cell
pinMode(ebOut, OUTPUT); //digital pin 1; to other endogenous burster cell
}
void loop(){
for (int x=0; x<180; x++) {
sinVal = (sin(radians(x)));
internalState = int(sinVal*255); //pwmVal is internal state of endogenously bursting cell
DigiKeyboard.print("SinVal=");
DigiKeyboard.println(sinVal);
DigiKeyboard.print("Output voltage to TA cell=");
DigiKeyboard.println(outputLevel);
DigiKeyboard.print("Output voltage to EB cell=");
DigiKeyboard.println(outputLevel);
DigiKeyboard.print("Input voltage="); //from SFA cell a or b
//should map to realistic voltages
DigiKeyboard.println(cell1Scaled);
DigiKeyboard.print("Resting State="); //print initial state of the cell
DigiKeyboard.println(internalState);
DigiKeyboard.print("Mean voltage=");
DigiKeyboard.println(avgScaled);
cell1Raw = analogRead(cell1);// input from SFA cell a or b
cell1Scaled = (cell1Raw / 4);
avgScaled = ((cell1Scaled + internalState) / 2); // calculate the average voltage of the 2 inputs and put it in avgScaled
/*if (avgScaled > 10) //set threshold to 10
{
outputLevel = IPSP; //inhibitory neuron activation leads to IPSP and synaptic weight of 0
}
else
{
outputLevel = noInput;
{
*/
outputLevel = 255;
analogWrite(taOut, outputLevel);
analogWrite(ebOut, outputLevel);
}}