Show Posts
Pages: [1] 2
1  Using Arduino / LEDs and Multiplexing / Re: 4-Digit Display Error on: October 04, 2012, 09:52:57 am
Thank you, tuxduino!

Your information explains a lot! I will try to get something out of that LED module soon.

In the meantime I chose to use an LCD screen smiley

All the best to you!
ygreq
2  Using Arduino / LEDs and Multiplexing / Re: 4-Digit Display Error on: October 02, 2012, 04:19:55 am
No problem. Actually I did google it like this "int8_t arduino". I only found examples that were not that great (I didn't understand anything). At least in the first 20 searches. I googled "int8_t" just now and there are a few info concerning int8_t in C/C++.

I will see if I understand what int8_t means.

Thank you!

PS: What I know of C/C++ comes from learning arduino. So I am trying to avoid as much as possible info that is for c/c++ and stick to proper libraries. (In this case I would say it is a crappy library.) I am not a C/C++ programmer unfortunately.
3  Using Arduino / LEDs and Multiplexing / Re: 4-Digit Display Error on: October 02, 2012, 03:48:03 am
Hi there,

Yeap. It seems it used 0 to 15 as hex as it ends up printing from 0 to F.

But the key to understanding both:

Code:
int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F
int8_t ListDisp[4];

is really understanding what int8_t stand for. Which I don't have a clue about. smiley-sad I am guessing it is not arduino lingo per se, but C.
4  Using Arduino / LEDs and Multiplexing / Re: 4-Digit Display Error on: October 02, 2012, 02:50:17 am
Hi fungus,

You mean to say that it needs something else? Do you maybe know what that is?

 From what is shown in the loop in the second sketch
Code:
int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F
int8_t ListDisp[4];

it seems it is a char.

Thank you!
ygreq
5  Using Arduino / LEDs and Multiplexing / Re: 4-Digit Display Error on: October 02, 2012, 02:00:48 am
Hi tuxduino,

Yes! I am very sure! Actually everything works (send to serial via Serial.print, send to an LCD following the same logic) except sending to that 7-segment module.

I am pretty sure that the answer is somewhat related to tm1637.display(0,inputString[0]); and how it is created in the first place.

Here is a sketch created by the makers of the module. Look at the end of the sketch how tm1637.display (0,ListDisp[0]); is used in that case.
It refers to int8_t ListDisp[4]; from the beginning.

What would be the difference between int8_t ListDisp[4]; and something like String ListDisp[4]; or char ListDisp[4]?

Thank you for looking into this!


Code:
//  Author:Frankie.Chu
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#include "TM1637.h"
#define CLK 2//pins definitions for TM1637 and can be changed to other ports       
#define DIO 3
TM1637 tm1637(CLK,DIO);
void setup()
{
  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
}
void loop()
{
  int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//0~9,A,b,C,d,E,F
  int8_t ListDisp[4];
  unsigned char i = 0;
  unsigned char count = 0;
  delay(150);
  while(1)
  {
    i = count;
    count ++;
    if(count == sizeof(NumTab)) count = 0;
    for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++)
    {
      ListDisp[BitSelect] = NumTab[i];
      i ++;
      if(i == sizeof(NumTab)) i = 0;
    }
    tm1637.display(0,ListDisp[0]);
    tm1637.display(1,ListDisp[1]);
    tm1637.display(2,ListDisp[2]);
    tm1637.display(3,ListDisp[3]);
    delay(300);
  }
}
6  Using Arduino / LEDs and Multiplexing / 4-Digit Display Error on: September 29, 2012, 03:27:38 pm
Hi,

I bought the following product from SeeedStudio: http://www.seeedstudio.com/wiki/Grove_-_4-Digit_Display
I have some problems with the following code. I don't get why something like tm1637.display(0,0); ends up displaying a 0 at the first digit of the 4-Digit_Display, but something like tm1637.display(1,x1); or tm1637.display(2,inputString[2]); displays only rubbish at the second and third digit.

Please help!!
Thank you for your input!
ygreq

Code:
/*
I started from the example from the link

http://www.arduino.cc/en/Tutorial/SerialEvent

Set to newline.

In this example you have to open the serial window and type 4 digits.
Ex: 1234 and press Enter.
See what happens on the serial monitor and on the 4-digit display 

*/

String inputString = "";         // a string to hold incoming data
char x1 = 0; // char to attribute to 2nd digit of the display

#include "TM1637.h"
#define CLK 2//pins definitions for TM1637 and can be changed to other ports       
#define DIO 3
TM1637 tm1637(CLK,DIO);




void setup() {
  // initialize serial:
  Serial.begin(9600);

  tm1637.init();
  tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
}


void loop() {

  if (Serial.available() > 0) {
    // get the new byte:
    char inChar = (char)Serial.read();
   
    // add it to the inputString:
    inputString += inChar;
   
 
    // if the incoming character is a newline,
     if (inChar == '\n') {
     
       Serial.print("string ");
       Serial.println(inputString); //print string
 
      tm1637.display(0,0); // display 0 on the first digit
     
      x1 = inputString[1]; // attach x1 to the second char in the string created
      Serial.print("2nd digit ");
      Serial.println(x1);  // print that second char to check if everything is ok
     
      tm1637.display(1,x1);// display the char attached to x1 on the second digit
                           // which does not work. Why??
      Serial.print("3rd digit ");
      Serial.println(inputString[2]);
      tm1637.display(2,inputString[2]);// display the char attached to 3rd char on
                              // the 3rd digit
                              // which does not work. Why??
       inputString = "";  // delete string
     
    }
  }
}
7  Using Arduino / Programming Questions / Re: SoftwareSerial Output -> process -> Serial.print on: June 12, 2012, 12:12:58 pm
I managed to modify some code I found that would hopefully help me solve this.

In order to manage this project better, I have now the following. What I want to achieve is in a sense the same as previous, but easier for people to get into.

Consider I use 2 XBees. One is sending data, the other one is receiving. The thing is I don't know how to modify the first sketch (the sender) so that it sends CR to terminate the string, or better yet modify the second sketch (the receiver) so that I use something else (not char 13) that I receive via serial to terminate the string or just add something to terminate it properly.



This code goes to the Arduino+XBee 1 that sends the data:

Code:
int SensorPin = 0; //analog sensor for detecting light
#include <SoftwareSerial.h>
SoftwareSerial XBeeSerial (3, 2);


void setup() {
  Serial.begin(9600);
  XBeeSerial.begin(9600);    //connection to Xbee shield
 
}

void loop() {
  int value = analogRead(temt6000Pin);
  String XBeeString = "Light: "; // I added this to the string in order to have something similar to the first example to process
  XBeeString += value;
  Serial.println(XBeeString);
  XBeeSerial.println(XBeeString);

  delay(100); //only here to slow down the output so it is easier to read
}



and this code goes to the Arduino+XBee 2 that receives the data:

Code:
#include <SoftwareSerial.h>
SoftwareSerial XBeeSerial (3, 2);



void setup() {

  Serial.begin(9600); // Initialize serial port
  XBeeSerial.begin(9600);
}

void loop()
{
  serialReader();
}

void serialReader(){
  int makeSerialStringPosition;
  int inByte;
  char serialReadString[50];
  const int terminatingChar = 13; //Terminate lines with CR

  inByte = XBeeSerial.read();
  makeSerialStringPosition=0;

  if (inByte > 0 && inByte != terminatingChar) { //If we see data (inByte > 0) and that data isn't a carriage return
    delay(100); //Allow serial data time to collect (I think. All I know is it doesn't work without this.)

    while (inByte != terminatingChar && XBeeSerial.available() > 0){ // As long as EOL not found and there's more to read, keep reading
      serialReadString[makeSerialStringPosition] = inByte; // Save the data in a character array
      makeSerialStringPosition++; //Increment position in array
      //if (inByte > 0) Serial.println(inByte); // Debug line that prints the charcodes one per line for everything recieved over serial
      inByte = XBeeSerial.read(); // Read next byte
    }

    if (inByte == terminatingChar) //If we terminated properly
    {
      serialReadString[makeSerialStringPosition] = 0; //Null terminate the serialReadString (Overwrites last position char (terminating char) with 0
      Serial.println(serialReadString);
     
    }
  }
}
8  Using Arduino / Programming Questions / Re: SoftwareSerial Output -> process -> Serial.print on: June 01, 2012, 03:23:07 am
Hi Grumpy_Mike,

Thank you for looking into this. I know a lil bit about the logic but I can't figure out how to actually implement it. I am stuck at gathering all the data into a string.

I did the following but it does not work. Does someone know how I should fix this?

Code:
#include <SoftwareSerial.h>

SoftwareSerial GeigerSerial (3, 2);

char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character


void setup()  {

  Serial.begin(9600); //connection to host computer
  Serial.println("Geiger ready");

  GeigerSerial.begin(9600);    //connection to Geiger shield

}


void loop() {
 
    if (GeigerSerial.available() > 0) // Don't read unless
                                       // you know there is data
    if(index < 19){
      inChar = GeigerSerial.read();
      inData[index] = inChar;
      index++;
      inData[index] = '\0'; // Null terminate the string
      Serial.print(inData[20]);
    }
    }
9  Using Arduino / Programming Questions / SoftwareSerial Output -> process -> Serial.print on: May 28, 2012, 09:41:51 am
Hi there,

I am trying to figure out how to extract the numbers I get from the Geiger Counter via SoftwareSerial so that I combine it with other info like for example an analog read from a light sensor.

I am guessing it implies using strings but I don't know how I should use them.

If I use the code below, I get for example "CPM: 16 CPS: 1" with a return at the end (CPM stand for counts per minute and CPS for counts per second).


But in the end I would like to send a string like this via Serial.print:

sensor1, 16
sensor2, 1
sensor3, 126

Code:
#include "SoftwareSerial.h"
SoftwareSerial GeigerCounter (3, 2);


void setup() {
    Serial.begin(9600);
    //connection to Xbee shield
    GeigerCounter.begin(9600);
   
}


void loop()
{
if (GeigerCounter.available()) {
      Serial.print((char)GeigerCounter.read());  //grab avail data from Geiger and send to host pc
  }



}
10  Using Arduino / Programming Questions / Re: ATmega C programming to Arduino lingo anyone? on: November 29, 2011, 10:04:32 pm
wow!

a bit weird that it compiles to Arduino Mega, and not Arduino Uno.

Thank you so much!

I have to go for a couple of days! I am packing up! I will give it a go when I return. smiley-grin

11  Using Arduino / Programming Questions / Re: ATmega C programming to Arduino lingo anyone? on: November 29, 2011, 08:35:45 pm
Hey, thank you Rob!

I checked your last sketch and it does not compile.

  DDRD |= (1<<PD3) | (1<<PD4);

Error: PD3 was not declared in this scope.

I might try to declare it at the beginning, but I am afraid it should be reformulated. I checked what PD3 stands for and it seems it is a Digital Pin. In our case it is, let's say, DigitalPin3. And it seems it's doing a PWM with those 2 digital pins. But than I hit a wall, because I don't understand this whole part:

Code:
int16_t reading;
  while(1) {
    // set polarity +-
    PORTD |= (1<<PD3);
    PORTD &= ~(1<<PD4);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delayMicroseconds(66);
    // take reading
    //reading = adc_read();
    Serial.print (adc_read());


    // set polarity -+
    PORTD |= (1<<PD4);
    PORTD &= ~(1<<PD3);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delayMicroseconds (66);
    // take reading
    //reading = reading - adc_read();
    Serial.println (adc_read());

    // send over serial port
    //printf_P(PSTR("%d\r\n"), reading);
  }

}
12  Using Arduino / Programming Questions / ATmega C programming to Arduino lingo anyone? on: November 29, 2011, 06:04:06 pm
Hey guys,

I am having difficulties understanding a code posted by the guys at nerdkits.com. They have a video tutorial about hacking a weight scale (see link: http://www.nerdkits.com/videos/weighscale/). And they give the code for the ATmega as well which I am having trouble understanding

Anyone willing to translate to Arduino lingo?
I think I understand where the part which creates the analog pins is, and there are other parts which I may understand, but the core is too much for me.
So maybe you can translate at least the main part where it does all the calculations (E.g. the switching of the polarity)
And can someone tell me if it says something else about the analog input besides creating it?

Thank you so much,
ygreq

Code:
// weighscale.c
// for NerdKits with ATmega168
// mrobbins@mit.edu

#define F_CPU 14745600

#include <stdio.h>

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"
#include "../libnerdkits/uart.h"

// PIN DEFINITIONS:
// PC0 -- analog in
//
// PD4 - bridge excite
// PD3 - bridge excite

void adc_init() {
  // set analog to digital converter
  // for external reference (5v), single ended input ADC0
  ADMUX = 0;

  // set analog to digital converter
  // to be enabled, with a clock prescale of 1/128
  // so that the ADC clock runs at 115.2kHz.
  ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);

  // fire a conversion just to get the ADC warmed up
  ADCSRA |= (1<<ADSC);
}

uint16_t adc_read() {
  // set ADSC bit to get the *next* conversion started
  ADCSRA |= (1<<ADSC);

  // read from ADC, waiting for conversion to finish
  // wait for it to be cleared
  while(ADCSRA & (1<<ADSC)) {
    // do nothing... just hold your breath.
  }
  // bit is cleared, so we have a result.

  // read from the ADCL/ADCH registers, and combine the result
  // Note: ADCL must be read first (datasheet pp. 259)
  uint16_t result = ADCL;
  uint16_t temp = ADCH;
  result = result + (temp<<8);

  return result;
}

int main() {
  // set PD3, PD4 as outputs
  DDRD |= (1<<PD3) | (1<<PD4);

  // init ADC
  adc_init();

  // init serial port
  uart_init();
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;


  int16_t reading;
  while(1) {
    // set polarity +-
    PORTD |= (1<<PD3);
    PORTD &= ~(1<<PD4);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delay_us(66);
    // take reading
    //reading = adc_read();
    printf_P(PSTR("%d "), adc_read());


    // set polarity -+
    PORTD |= (1<<PD4);
    PORTD &= ~(1<<PD3);
    // wait 5 time constants (bw=12kHz, T=13.2us)
    delay_us(66);
    // take reading
    //reading = reading - adc_read();
    printf_P(PSTR("%d\r\n"), adc_read());

    // send over serial port
    //printf_P(PSTR("%d\r\n"), reading);
  }

  return 0;
}
13  Using Arduino / Sensors / Re: Detecting Proximity to Specific Object on: November 26, 2011, 06:01:20 am
Yeap, like Magician said, a cheap solution would be a Hall effect sensor (aka magnetic fields). Your object would have the magnet inside and the dock would have the sensor. Check proximity range for different types of Hall sensors.
14  Using Arduino / Sensors / Re: How do I hack a body weight scale? on: November 26, 2011, 05:51:43 am
I found this schematic that uses a PIC MCU. It seems to be for a body scale as it uses CS3002 Amp to amplify the load cells' signal.

Can you tell if it is any good and maybe how to change the PIC for an Arduino in this schematic?

1.I don't get why the E- is not present (you can see E+, S-, S+), but instead it is GND (check bottom left corner). Is this normal?
2.Also, as Arduino has the ATmega built in, what do I need from this schematic and should I put aside? I am guessing I don't need the crystal, for example, as it is already integrated in the arduino.
3.What should the code on the arduino look for or measure?

Any help is truly appreciated!
Or if anyone has any other ideas?
15  Using Arduino / Sensors / How do I hack a body weight scale? on: November 25, 2011, 06:47:40 am
Hi guys!

I am trying to figure out how I can interact with 4 load sensors (like this http://manyyear.en.alibaba.com/product/359992876-210312211/MLC902_Micro_sensor.html. I think this might be similar to this one: http://www.sparkfun.com/products/10245

I am actually trying to hack a body weight scale which looks pretty similar to this one (see attached pic or link http://www.dietsinreview.com/diet_column/wp-content/uploads/2009/09/escali-track-and-target-scale.jpg)

I just want to use it with arduino so either just replacing the original board or trying to get the output from the original pcb to use as input to arduino will work for me. Specifically I want to output to serial from Arduino to the computer.

There are loads of info about the subject on the net, but none of it helps as they mostly relate to other prototyping boards.

Here are some links you can find on the net:

http://www.nerdkits.com/videos/weighscale/ this is not ok from the start as it uses a 1 load sensor instead of 4. Really interesting tutorial video, though!

http://cerulean.dk/words/?page_id=42 Another good tutorial! Unfortunately it uses another type of sensor and, again, it uses a single sensor.

http://scanlime.org/2010/01/hacking-a-digital-bathroom-scale/ Really nice hacking project! Unfortunately again, here she uses a different prototyping board and, even though she presents the hack as simple, I have a different body weight scale, so I am a bit confused.

http://code.google.com/p/casainho-projects/wiki/SdCardBathroomScale This body weight scale looks pretty similar to mine! And the hack is really good. From what I understand, he is hacking into the info goind to the original LCD. But again, using different board and lots of cables smiley

Any thoughts? Anybody finished a project like this?

Pages: [1] 2