Requesting assist with Noise Click programs/codes

General discussion on Libstock website & codes posted on this website.
Post Reply
Author
Message
Shahrizone
Posts: 4
Joined: 26 Jun 2019 09:25

Requesting assist with Noise Click programs/codes

#1 Post by Shahrizone » 26 Jun 2019 09:39

Hi everyone, i'm currently working with Noise Click sensor and i'm stuck with the sample program as i'm trying to display "Normal" and "Noise Detect" to the LCD display..below is the program that i'm working on. Can anyone please help me with code or any code that is easier to understand using this click board..your assistance is really appreciate..Thank you

// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End Lcd module connections


sbit NOISE_CS at LATE0_bit;
sbit NOISE_CS_DIR at TRISE0_bit;
sbit NOISE_INT at RB0_bit;
sbit NOISE_INT_DIR at TRISB0_bit;


void system_setup( void );

void main()
{
//Local Declarations
uint8_t buffer[20] = { 0 };
uint32_t value = 0;
uint16_t threshold = 300;

//Setup
system_setup();
noise_set_threshold( threshold );

//Loop
while(1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display

value = ADC_Read( 2 );

LongToStr( value, buffer );
Lcd_Out(2,6,buffer ); // Write text in second row
Delay_ms(1000);

if( NOISE_INT == 0 ); // Do nothing
else
Lcd_Out(2,6,"Detect!"); // Write text in second row

}

}

void system_setup( void )
{


//GPIOs
NOISE_CS_DIR = 0;
NOISE_INT_DIR = 1;

//SPI
SPI1_Init_Advanced( _SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE,
_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH );
Delay_ms(200);

//ADC
ADC_Init();
Delay_ms(200);

//Noise Click
noise_init();


//LCD setup
ANSELB = 0; // Configure PORTB pins as digital


Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
//Lcd_Out(1,6,"LCD Initialized"); // Write text in first row

}

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Requesting assist with Noise Click programs/codes

#2 Post by jovana.medakovic » 04 Jul 2019 16:16

Hello,

Can you tell me which MCU and development system you are using?
I tested your code with PIC18F87K22 and it works fine.

Can you tell me, did you get some result on your LCD?

Kind regards,
Jovana

Shahrizone
Posts: 4
Joined: 26 Jun 2019 09:25

Re: Requesting assist with Noise Click programs/codes

#3 Post by Shahrizone » 05 Jul 2019 02:33

Hello and thank you for your reply,

I tested the code using PIC18F87K22 and as you said before,it worked fine. There is no problem with the code actually.The only thing that I require is that the code should display "Noise Detected" if the value above the threshold and "Normal" if the value within the range of the threshold. I try to modify the sample code provided but the result was not as i needed. Is there any way that I can do to modify the code with this Noise click as I need to combine it with other sensors for my project. The example below is the code that I try to modify.

while(1)
{
Lcd_Cmd(_LCD_CLEAR); // Clear display

value = ADC_Read( 2 );

LongToStr( value, buffer );

Delay_ms(1000);

if( NOISE_INT == 0 ){
Lcd_Out(2,6,"Normal");
Lcd_Out(buffer);

}
else if(NOISE_INT >= 300){
Lcd_Out(2,6,"Noise Detect!"); // Write text in second row
}
}

Thank you for your assistance.

Regards,
-Shahrizone-

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Requesting assist with Noise Click programs/codes

#4 Post by jovana.medakovic » 05 Jul 2019 11:55

Hello,

If you use our EasyPIC PRO v7 development board, you can see that RB0 pin is using for interrupt and also for LCD, so there is a problem.
You can solve that if you change RB0 pin for LCD to another pin, for example, RC0 and connect LCD with the board using wire jumpers.

In the attachment, you can find a package for PIC for this click board and source code. Install the .mpkg file from the archive and open the example from the compiler.

I have also attached the main .c file that I altered so data would be output to LCD, you can copy/paste the code from that file, or replace the file entirely.

Kind regards,
Jovana
Attachments
Click_Noise_PIC.zip
(1.35 KiB) Downloaded 118 times
library.zip
(197.47 KiB) Downloaded 110 times

Shahrizone
Posts: 4
Joined: 26 Jun 2019 09:25

Re: Requesting assist with Noise Click programs/codes

#5 Post by Shahrizone » 05 Jul 2019 14:21

Hello Jovana,

I want to thank you for your assistance..For your information,I'm using EasyPic 7 when I'm developing the modify version of the code. After i try using the code that you attached and do a little bit of modifying to make it more compatible with my development board, the code works well for me. Thank you again for your help in this matter, i really appreciate it.

Sincerely,
-Shahrizone-

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Requesting assist with Noise Click programs/codes

#6 Post by jovana.medakovic » 05 Jul 2019 14:57

Hi,

I'm glad that your problem is solved.
If you have additional question, feel free to ask.

Kind regards,
Jovana

Post Reply

Return to “Libstock Discussion”