# Digital Fat Calliper Sensor

Discussion in 'Electronic Projects Design/Ideas/Reviews' started by vivian_lys90, Jan 19, 2013.

1. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi,

For the fat matrix scale, there consists of 64 thin strips. I found that the distance between 2 strip is 0.78mm. My question is, how should I write the programming code so that the microcontroller can get the distance?
I really need help from you all. Thanks.

Vivian

2. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
If nRBPU isn't found, try RBPU = 0; it is the top bit in OPTION_REG in any case. The WPUB bits default to 1, so you don't need to worry about them.

The calliper draws an arc with the moving arm; therefore you should get the total angle spanned by the 64 switches and divide by 64. This will be the effective angle per switch.

To calculate the skin thickness you also need the distance from the calliper's rotation point to the end of the arm (that end that touches the skin). You then apply some maths (http://www.mathopenref.com/chord.html) and get the chord length, which is the skin thickness. Use a 64 entry lookup table rather than calculating the values in your code.

• Like x 1
3. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hello,

I want to shows the value of age and gender in my LCD. And the user can change the value of age and gender by pressing the tact switch. Can I know how should I program my LCD so that it's value can be adjusted??

Vivian

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

Joined:
Nov 14, 2012
Messages:
75
Likes:
0

Hi Doug,

6. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi,

I have question about this fat matrix charliplexing. Assume one of the button in D5 is pressed, how the charlieplexing works in order to send the signal to the microcontroller? How the microcontroller know which of the button is pressed??

Vivian

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hello.,

8. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi Doug,

For the fat matrix coding that you have wrote, how to make the return value to be displayed on the LCD display?
Thanks a lot.

Vivian

9. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
You need to learn how to program in C first.

To display information on the LCD, you will first need to initialise it, then write the numeric data (the value returned from the readCalliper() function converted to ASCII characters). Hopefully someone can provide you with direction in this regard.

10. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0

This is the editted code. But I failed to show which button has been pressed.

11. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
It's good to see that you have access to an LCD library. In http://www.mikroe.com/download/eng/documents/compilers/mikroc/pro/pic/help/lcd_library.htm, they make sure to configure all analogue pins (e.g. comparator and ADC) as digital - make sure to do that for all the pins you are using for the matrix and for the LCD.

To display the caliper value, I'd perhaps use the following:
Code (text):
char valueText[4] = {'0' + (value/100), '0' + ((value / 10) % 10), '0' + (value % 10), 0};
Lc_Out(1,8,valueText);

Last edited: Apr 24, 2013
• Like x 1
12. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi Doug,

I tried to use your code, but it come out with an error, which is 'Const expression expected'.

13. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
The lines of code I provided would go inside the main() function. I omitted the final zero in the declaration of valueText[] (changed above).

If you still get the same compilation error, then you can use the following in place of the declaration of valueText[].
Code (text):
char valueText[4];
valueText[0] = '0' + (value/100);
valueText[1] = '0' + ((value / 10) % 10);
valueText[2] = '0' + (value % 10);
valueText[3] = 0;
If you want to continuously display the changing value, you'll have to place the readCalliper() and Lcd_Out() functions in a loop (and include a delay).

• Like x 1
14. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi Doug,

The error 'Const expression expected' is come from the code:
Before that you are writing 'uint_t value=readCalliper() ', but it come out with the error ' Undeclared identifier 'uint_t' in expression'.

15. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
That code would go in the main() function.

uint8_t is the same as unsigned char if #include <stdint.h> is included in the code.

• Like x 1
16. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi Doug,

What is this refer to?
The code can be run now. But the number of button pressed does not display out.
Attached pic is the design when perform the simulation

17. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0

This is the code that use to simulate the circuit.

18. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
Code (text):
void main()
{

ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,"25");
Lcd_Out(1,6,"F");
Lcd_Out(1,13,"BF%");

while(1)
{
// get new value
char valueText[4];
valueText[0] = '0' + (value/100);
valueText[1] = '0' + ((value / 10) % 10);
valueText[2] = '0' + (value % 10);
valueText[3] = 0;

// display new value
Lcd_Out(2,2,valueText);

// throttle update rate to stop the display from blurring
Delay_ms(100);
}

• Like x 1
19. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi Doug,

Thanks for the edited code. But it still no number of button display when I pressed the button. Will it because there is no power supply to the fat matrix? Or because no output is send to the LCD?
Sorry to disturb.

20. ### vivian_lys90New Member

Joined:
Nov 14, 2012
Messages:
75
Likes:
0
Hi,

Below is my problem:
1) The number of button pressed will recount start from 0 when reached diode 5-8.

Attached is my edited circuit design:

And this is the picture for the problem occured:
Button on diode 1 is pressed:

Button on diode 5 is pressed:

Below is the code I use to run the simulation:

#### Attached Files:

File size:
47.8 KB
Views:
99
• ###### jj.jpg
File size:
46.5 KB
Views:
102
Last edited: Apr 28, 2013
21. ### dougy83Well-Known Member

Joined:
May 18, 2008
Messages:
2,672
Likes:
215
Location:
Brisbane, Australia
Hi Vivian,

Sorry, but I can't run the design you provided as there seems to be limitations in the demo version of Proteus.

I can tell you that the resistors connected to PORTA should be connected to 5V and not to ground as you have done. The direction of the diodes should also be corrected.

I will have a look at the code at a later date to see if there are any obvious bugs in the function I provided.

Cheers,
Doug