erorr on platformIO ide - arduino-uno

Hello everyone I wrote the following code in platformIO IDE to read a value from the YL-69 module and display it in 7segment, but I got this error:
error: no 'void SevenSegmentFun::bouncingBall(uint16_t, uint16_t, bool)' member function declared in class 'SevenSegmentFun'
#include <Arduino.h>
#include "SevenSegmentTM1637.h"
const byte PIN_CLK = 2; // define CLK pin (any digital pin)
const byte PIN_DIO = 3; // define DIO pin (any digital pin)
SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);
void setup() {
Serial.begin(9600);
display.begin();
display.setBacklight(100);
display.print("INIT");
delay(1000);
display.clear();
// wait 1000 ms
pinMode(A0,INPUT);
};
// run loop (forever)
void loop() {
int i=analogRead(A0);
display.print(i);
delay(1000);
};
What is wrong? and How can i fix it?

Related

Arduino Led Cube 5x5x5 shift register 74HC595

I'm working on an Arduino project led cube 5x5x5 using shift register 74HC595 I write a function to turn one led on or off the problem is when I want to turn on two led in different layer 4 led turn on how I can solve that
#include <ShiftRegister74HC595.h>
// create a global shift register object
// parameters: <number of shift registers> (data pin, clock pin, latch pin)
ShiftRegister74HC595<4> sr(11, 13, 8);
const uint8_t L0 = A0;const uint8_t L1 = A1;
const uint8_t L2 = A2;const uint8_t L3 = A3;
const uint8_t L4 = A4;
static const uint8_t layers[] = {L0,L1,L2,L3,L4};
const int delaytime=10;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int i=0;i<5;i++)
pinMode(layers[i],OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
setLedState(0,L4,true);
setLedState(12,L1,true);
}
void setLedState(int lednum,uint8_t layer,bool state)
{
if(state==true)
{
sr.set(lednum,HIGH);
digitalWrite(layer,HIGH);
}else
{
sr.set(lednum,LOW);
digitalWrite(layer,LOW);
}
}

Attiny85 with ArduinoUno for I2c comm

I am working on attiny85 for I2C communication. I have gone through different libraries already like Wire.h, TinyWire.h, tinyWireM.h, tinyWireS.h.
In the start I want to send some byte of data through I2C comm and tried to scope the pin with oscilloscope but its not giving me the appropriate results. Looking on the internet about different ways to make attiny85 work with I2c is really heartless and I could not achieve the task. Finally, I tried to make attiny85 as master and arduino Uno as slave as it was spare in my box.
I tried to make attiny85 as master and send data to arduino and looks the output on serial monitor but its showing zero.
For the reference, the master and slave codes are attached and my task is just simple to check on serial.
Attiny85 as Master
#include <TinyWireM.h>
void setup()
{
TinyWireM.begin();
}
void loop()
{
TinyWireM.begin();
TinyWireM.beginTransmission(0x08);
TinyWireM.send(0x99);
int Byte1 = TinyWireM.endTransmission();
delay(1000);
}
Arduino as Slave
#include <Wire.h>
const byte add = 0x08;
int byte1;
void setup()
{
Wire.begin(add);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
}
void loop()
{
Serial.println ("Data receiving");
Serial.println(byte1);
delay(1000);
}
void receiveEvent(int bytes)
{
byte1 = Wire.read();
}
But I am not able to get the output on serial monitor of arduino.
What am i doing wrong here?
I have used Atiny85 as a slave using TinyWireS lib (https://github.com/nadavmatalon/TinyWireS) some time back and it worked fine.
Below were the pin configurations
ATtiny85 pin 5 with Arduino Uno A4 and
ATtiny85 pin 7 with Arduino Uno A5
Below are my codes
Atiny.
#include "TinyWireS.h"
const byte SLAVE_ADDR = 100;
const byte NUM_BYTES = 4;
volatile byte data = { 0, 1, 2, 3 };
void setup() {
TinyWireS.begin(SLAVE_ADDR);
TinyWireS.onRequest(requestISR);
}
void loop() {}
void requestISR() {
for (byte i=0; i<NUM_BYTES; i++) {
TinyWireS.write(data[i]);
data[i] += 1;
}
}
Uno.
#include <Wire.h>
const byte SLAVE_ADDR = 100;
const byte NUM_BYTES = 4;
byte data[NUM_BYTES] = { 0 };
byte bytesReceived = 0;
unsigned long timeNow = millis();
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.print(F("\n\nSerial is Open\n\n"));
}
void loop() {
if (millis() - timeNow >= 750) { // trigger every 750mS
Wire.requestFrom(SLAVE_ADDR, NUM_BYTES); // request bytes from slave
bytesReceived = Wire.available(); // count how many bytes received
if (bytesReceived == NUM_BYTES) { // if received correct number of bytes...
for (byte i=0; i<NUM_BYTES; i++) data[i] = Wire.read(); // read and store each byte
printData(); // print the received data
} else { // if received wrong number of bytes...
Serial.print(F("\nRequested ")); // print message with how many bytes received
Serial.print(NUM_BYTES);
Serial.print(F(" bytes, but got "));
Serial.print(bytesReceived);
Serial.print(F(" bytes\n"));
}
timeNow = millis(); // mark preset time for next trigger
}
}
void printData() {
Serial.print(F("\n"));
for (byte i=0; i<NUM_BYTES; i++) {
Serial.print(F("Byte["));
Serial.print(i);
Serial.print(F("]: "));
Serial.print(data[i]);
Serial.print(F("\t"));
}
Serial.print(F("\n"));
}

Using PuTTY to print from STM32

I want to print messages from my STM32 Nucleo-L073RZ microcontroller. How should I go about it?
Should I use UART? Where can I get the corresponding code?
#include "stm32l0xx.h"
#include "stm32l0xx_nucleo.h"
#include "stm32l0xx_hal.h"
#include "stdio.h"
static void GPIO_Init (void);
static void UART_Init (void);
int main(void)
{
HAL_Init();
GPIO_Init();
printf("Hello");
while(1)
{
}
}
static void GPIO_Init(void)
{
BSP_LED_Init(LED2);
BSP_LED_On(LED2);
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin : PA13*/
GPIO_InitStruct.Pin = GPIO_PIN_13;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
}
/*Uart Init Function*/
static void UART_Init(void)
{
}
void EXTI4_15_IRQHandler(void)
{
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_PIN)
{
BSP_LED_Toggle(LED2);
counter();
}
int counter()
{
int i;
i = 0;
i++;
printf("/n %d", i);
}
How do I display the counter on my PC? I want the number of times the interrupt is given to be seen on PuTTY. Should I interface an UART or is it possible to print?
You can use UART on the Nucleo
All Nucleo boards have a built-in UART-to-USB module that automatically transmits data to a Serial Port on your computer. If on windows, open your Control Panel, go to Device Manager, and under COM Ports you should see your Nucleo.
Initialize the UART Peripheral
Reference your Nucleo user manual to see which UART pins connect to the USB port (STM32CubeMX might have these already mapped).
When initializing the peripheral, select a baud rate like 9600, and remember it
Configure PuTTy
Enter the COM port of the Nucleo and the Baud Rate that you selected earlier, and select Serial as the transmission method. You might have to disable some of the hardware flow control options if they are enabled
Code to transmit
HAL has functions for transmitting over UART. Something like HAL_UART_Transmit(...). You'll have to look up how to use the function specifically, plenty of great tutorials out there.
I personally use sprintf to print nicely formatted strings over UART like this:
char buf[64];
sprintf(buf, "Value of counter: %d\r\n", i);
// change huartX to your initialized HAL UART peripheral
HAL_UART_Transmit(&huartX, buf, strlen(buf), HAL_MAX_DELAY);
First Add use UART Handler and its init in this function i used UART2 change it to your periph if you use Stm32 Cube or IDE just select the periph it is automatically generated.
Use this function in order to use the print function it's act the same like Printf.
#include <stdint.h>
#include <stdarg.h>
void printmsg(char *format,...) {
char str[80];
/*Extract the the argument list using VA apis */
va_list args;
va_start(args, format);
vsprintf(str, format,args);
HAL_UART_Transmit(&huart2,(uint8_t *)str, strlen(str),HAL_MAX_DELAY);
va_end(args);
}
In your Counter function just Change printf to printmsg
int counter()
{
int i;
i = 0;
i++;
printmsg("/n %d", i);
}
Remember to change Printmsg uart Handler .

Arduino 1.6.9/1.610 build fails with "'constexprint' does not name a type"

Supposedly Arduino's IDE > 1.6.2 has C++11 support.
I have just freshly downloaded and run version 1.6.9 on OSX (and as others have reported, this repros on Windows as well, with 1.6.9/1.6.10).
I cannot get this simple program to compile:
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}
I receive this error when I try to build or upload:
sketch_jul25a:1: error: 'constexprint' does not name a type
constexpr int get_five() { return 5; }
^
exit status 1
'constexprint' does not name a type
I've looked at this question and answer, but it is supposedly no longer applicable in 1.6.9 version of the IDE that I am using - error: 'constexpr' does not name a type m- arduino ide
I have dug into the temporary files that are output by the IDE when building, and it seems it is trying to automatically generate headers for functions (I assume for multi-file sketch support), and does the wrong thing when it encounters constexpr:
#include <Arduino.h>
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
constexprint get_five(); // **** <- This looks to be the culprit
#line 3 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
void setup();
#line 9 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
void loop();
#line 1 "/Users/<my_username>/Documents/Arduino/sketch_jul25a/sketch_jul25a.ino"
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}
Is this a bug in the Arduino IDE? Is it unique to OSX? Is there a workaround that allows constexpr to work?
In googling I have found that some Arduino libraries are using constexpr, so I am assuming it could be made to work in some cases.
This is a known limitation of the arduino-builder.
Until it is fixed, you can add a prototype yourself above the function. This will prevent the IDE from incorrectly generating its own.
constexpr int get_five();
constexpr int get_five() { return 5; }
void setup() {
Serial.begin(9600);
Serial.println(get_five());
}
void loop() {
}

User space netlink socket receives empty messages from kernel space

Disclaimer - I have to admit that it's the 1'st time I'm using this kernel interface (socket).
I'm currently working on a design of a kernel module that is based on a netlink socket .
I'm using Ubuntu14.04 and linux kernel 4.
As a starter, I wanted to make sure that I can use the netlink socket in both directions.
I've written an application that does the following:
1) User send a message to kernel via the netlink socket.
2) Kernel, upon receiving the message – sends "ABCD" string message to a workqueue.
3) When the "ABCD" message is received by the workqueue, it calls a function (named - my_wq_function) which send it back to the user space via netlink socket.
4) In the user space I'm using a recvmsg function (blocking until a message is received) and displays the "ABCD" message.
My problem is that the return value from the recvmsg function is 20 (instead of 4), and the data itself (i.e. NLMSG_DATA) is empty.
During the debug I tried to change the message to "ABCD1234" and got a return value of 24 bytes, however the data is still empty.
I also verified that my entire path until the point of sending the "ABCD" from kernel to the socket is OK.
Not sure what I'm doing wrong here & will highly appreciate your help.
Thanks in advance, MotiC.
my code example can be found below:
User space code:
printf("netlink receiver thread started...\n");
nlh_rcv = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));
while(true) //endless loop on netlink socket
{
memset(nlh_rcv, 0, NLMSG_SPACE(MAX_PAYLOAD));
iov_rcv.iov_base = (void *)nlh_rcv;
iov_rcv.iov_len = nlh_rcv->nlmsg_len;
msg_rcv.msg_name = (void *)&dest_addr;
msg_rcv.msg_namelen = sizeof(dest_addr);
msg_rcv.msg_iov = &iov;
msg_rcv.msg_iovlen = 1;
ret=recvmsg(sock_fd, &msg_rcv, 0);
printf("errno=%i bytes=%i message from kernel: %s\n",errno, ret, (char*)NLMSG_DATA(nlh_rcv));
uint8_t mymsg[100];
memcpy(mymsg, NLMSG_DATA(nlh_rcv), 100);
printf("message from kernel: %s\n",mymsg);
}
Kernel space code:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
#include <net/sock.h>
#include <linux/socket.h>
#include <linux/net.h>
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>
#include <linux/workqueue.h>
MODULE_LICENSE("GPL");
#include "rf_Kdriver_main.h"
//------ definitions ------------------------------------------------------------------------------------------------------------
#define NETLINK_USER 31
#define MAX_PAYLOAD 1024 /* maximum payload size*/
struct sock *nl_sk = NULL;
struct nlmsghdr *nlh;
struct nlmsghdr *nlh_out;
struct sk_buff *skb_out;
char buf_to_user[100];
int pid;
//------------------------------------------------------------------------------------------------------------------------------
struct workqueue_struct *my_wq;
typedef struct {
struct work_struct my_work;
uint8_t msg_to_pc[128];
uint8_t msg_len;
} my_work_t;
my_work_t *work, *work2;
//-----------------------------------------------------------------------------------------------------------------------------
static void my_wq_function( struct work_struct *work)
{
int res;
my_work_t *my_work = (my_work_t *)work;
skb_out = nlmsg_new(my_work->msg_len,0);
if (!skb_out)
{
printk("Failed to allocate new skb\n");
return;
}
nlh_out = nlmsg_put(skb_out, 0, 0, NLMSG_DONE,my_work->msg_len, 0);
NETLINK_CB(skb_out).dst_group = 0;
memcpy((char*)NLMSG_DATA(nlh_out), my_work->msg_to_pc , my_work->msg_len);
printk( "dequeue message to pc=%s len=%i\n", (char*)NLMSG_DATA(nlh_out), (int)strlen((char*)NLMSG_DATA(nlh_out)));
res = nlmsg_unicast(nl_sk, skb_out, pid);
if (res<0)
printk("Failed to send message from kernel to user\n");
kfree( (void *)work );
return;
}
//-----------------------------------------------------------------------------------------------------------------------------
int send_up_msg_to_workque(uint8_t msg_to_pc[], uint8_t msg_len)
{
int ret=0;
work = (my_work_t *)kmalloc(sizeof(my_work_t), GFP_KERNEL);
if (work) {
INIT_WORK( (struct work_struct *)work, my_wq_function );
memcpy(work->msg_to_pc, msg_to_pc, msg_len);
work->msg_len = msg_len;
ret = queue_work( my_wq, /*(struct work_struct *)RR*/work );
printk("kuku ret=%i msg=%s\n",ret,work->msg_to_pc);
}
return ret;
}
//------------------------------------------------------------------------------------------------------------------------------
static void netlink_recv_msg(struct sk_buff *skb)
{
char *msg = "ABCD1234";
printk(KERN_INFO "Entering: %s\n", __FUNCTION__);
nlh=(struct nlmsghdr*)skb->data;
printk(KERN_INFO "Netlink at kernel received msg payload: %s\n",(char*)NLMSG_DATA(nlh));
//rr
pid = nlh->nlmsg_pid;
send_up_msg_to_workque((uint8_t*) msg, strlen(msg));
}
//-------------------------------------------------------------------------------------------------------------------------------------
struct netlink_kernel_cfg cfg = {
.input = netlink_recv_msg,
};
static int __init rf_driver_start(void)
{
printk(KERN_INFO "Loading RF Driver module1...\n");
my_wq = create_workqueue("my_queue");
if (!my_wq)
{
printk("Failed to create work queue\n");
}
printk("Entering: %s\n",__FUNCTION__);
nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);
if(!nl_sk)
{
printk(KERN_ALERT "Error creating socket.\n");
return -10;
}
return 0;
}
//--------------------------------------------------------------------------------------------------------------
static void __exit rf_driver_end(void)
{
netlink_kernel_release(nl_sk);
flush_workqueue(my_wq);
destroy_workqueue(my_wq);
printk(KERN_INFO "RF Driver exit...\n");
}
module_init(rf_driver_start);
module_exit(rf_driver_end);
Update,
I changed my user space function to:
char buf[100];
ret=recv(sock_fd, buf, 100, 0);
instead of:
ret=recvmsg(sock_fd, &msg_rcv, 0);
and it works...
does anyone have an idea regarding this strange behavior ?
Thanks.
Can you please paste complete userspace code.
I guess 'len' int this code is the issue:
memset(nlh_rcv, 0, NLMSG_SPACE(MAX_PAYLOAD));
iov_rcv.iov_len = nlh_rcv->nlmsg_len; << check to what value is it getting initialized.

Resources