Uno Convert to Mega

Hi Team

I have a library which was written for Arduino Uno

So i need to modify it for Aeduino Maga, Can I have idea to do so

Is there any common algorithm or any documentation
Thanks in advanced

Please share the details of the library

What does it do and where is it available to examine ?

1 Like

It is written for line following root
I am uploading it using ISP port using usbasp programmer

Please share the library

Depending on how it's written and what hardware ressources it depends on, may be it will work as is. Without the code we can't help.

1 Like

I am locking to upload the liberty but it does not allow

Can any one help me to upload the library

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

If you downloaded the library then please post a link to where it is available

...in the meanwhile, just start telling us if you installed manually or from Library Manager, and post here the exact library title and the name of the author so we could search it on Library manager and/or Gihub.

1 Like

Library Name is D Cube Robot
The installation done by manually
Library path C:\Users\user\Documents\Arduino\hardware
author PADL Palihawadana

Any link to GitHub you can share?

1 Like

Not available in the GitHub

It was given to my son by his teacher

Copy and paste the code here within code tags. (mention the file name)
if there are multiple files, just create multiple code tags sections

file1.h

some code here
some code here
some code here

file1.cpp

some code here
some code here
some code here

...

1 Like

There are so many folders

image

Not found on Github.
It's just a Sri Lanka robotics school and "Makerspace":
https://dcube.lk/
There's no information at all, the site has some empty pages (including "products") and many broken links on the footer menu.
I think there's no easy way to have that converted for Mega (even if I still can't get what you need to do...).

Hear are "DCubeDigital" folder files

1 DcubeDigital.cpp

/*
  DcubeDigital.cpp - Library for using the motor drivers on the
  Dcube stem robot
	
		setOutput(3, HIGH);
	
	compiles to the assembly:
	
		sbi 0x0b, 3  ;i.e. PORTD |= 1 << 3;
		sbi 0x0a, 3  ;i.e. DDRD  |= 1 << 3;
	
	In short, if your inputs are constants, you can use this library in
	place of raw digital I/O register manipulation without worrying
	about any significantly increased overhead or processing time.
	Using variables as inputs can increase overhead and processing time,
	but the methods in this library can lead to easier to write (and
	read) programmatic approaches to dealing with digital I/O.
	
	The digital pins on the AVR default to high-impedance inputs after
	a power-up or reset.
*/
/*
 * Written and modify by PADL Palihawadana, May 1, 2017.
 * Copyright (c) 2012-2022 DCube Robotics. For more information, see
 *
 *   http://www.dcube.lk

 *
 * You may freely modify and share this code, as long as you keep this
 * notice intact (including the link above).  Licensed under the
 * Creative Commons SLR 1.0 license:
 *

 *
 * Disclaimer: To the extent permitted by law, DUbe provides this work
 * without any warranty.  It might be defective, in which case you agree
 * to be responsible for all resulting costs and damages.
 */

 

#include "DcubeDigital.h"


// constructor
DcubeDigital::DcubeDigital()
{

}


// Local Variables: **
// mode: C++ **
// c-basic-offset: 4 **
// tab-width: 4 **
// indent-tabs-mode: t **
// end: **

DcubeDigital.h

/*
  DcubeDigital.cpp - Library for using the digital I/O lines on the
	Dcube LV, SV, SVP, X2, Baby Dcube B, or 3pi robot.  The code
	is all inline, which lets it compile to very small, fast, efficient
/*
  DcubeDigital.cpp - Library for using the motor drivers on the
  Dcube stem robot
	
		setOutput(3, HIGH);
	
	compiles to the assembly:
	
		sbi 0x0b, 3  ;i.e. PORTD |= 1 << 3;
		sbi 0x0a, 3  ;i.e. DDRD  |= 1 << 3;
	
	In short, if your inputs are constants, you can use this library in
	place of raw digital I/O register manipulation without worrying
	about any significantly increased overhead or processing time.
	Using variables as inputs can increase overhead and processing time,
	but the methods in this library can lead to easier to write (and
	read) programmatic approaches to dealing with digital I/O.
	
	The digital pins on the AVR default to high-impedance inputs after
	a power-up or reset.
*/
/*
 * Written and modify by PADL Palihawadana, May 1, 2017.
 * Copyright (c) 2012-2022 DCube Robotics. For more information, see
 *
 *   http://www.dcube.lk

 *
 * You may freely modify and share this code, as long as you keep this
 * notice intact (including the link above).  Licensed under the
 * Creative Commons SLR 1.0 license:
 *

 *
 * Disclaimer: To the extent permitted by law, DUbe provides this work
 * without any warranty.  It might be defective, in which case you agree
 * to be responsible for all resulting costs and damages.
 */

#ifndef DcubeDigital_h
#define DcubeDigital_h

#include "../DcubeResources/include/DcubeModel.h"
#include <avr/io.h>

#define INPUT 				0
#define OUTPUT				1
#define LOW					0
#define HIGH				1
#define TOGGLE				0xFF
#define HIGH_IMPEDANCE		0
#define PULL_UP_ENABLED		1

// port D pins
#define IO_D0				0
#define IO_D1				1
#define IO_D2				2
#define IO_D3				3
#define IO_D4				4
#define IO_D5				5
#define IO_D6				6
#define IO_D7				7

// port B pins
#define IO_B0				8
#define IO_B1				9
#define IO_B2				10
#define IO_B3				11
#define IO_B4				12
#define IO_B5				13


#if defined(_Dcube_SVP) || defined(_Dcube_X2)

#define IO_B6				14
#define IO_B7				15

// port C pins
#define IO_C0				16
#define IO_C1				17
#define IO_C2				18
#define IO_C3				19
#define IO_C4				20
#define IO_C5				21
#define IO_C6				22
#define IO_C7				23

// port A pins
#define IO_A0				31
#define IO_A1				30
#define IO_A2				29
#define IO_A3				28
#define IO_A4				27
#define IO_A5				26
#define IO_A6				25
#define IO_A7				24

#else

// port C pins
#define IO_C0				14
#define IO_C1				15
#define IO_C2				16
#define IO_C3				17
#define IO_C4				18
#define IO_C5				19
#define IO_C6				20	// only used if RESET pin is changed to be a digital I/O

#endif


struct IOStruct
{
	// if these aren't volatile, the compiler sometimes incorrectly optimizes away operations involving these registers:
	volatile unsigned char* pinRegister;
	volatile unsigned char* portRegister;
	volatile unsigned char* ddrRegister;
	unsigned char bitmask;
};

#ifdef __cplusplus

class DcubeDigital
{
  public:

    // constructor (doesn't do anything)
	DcubeDigital();
	
	
	// gets a structure with pointers to the three digital I/O registers associated
	// with the specified pin (DDR, PORT, and PIN) along with a bitmask with a
	// 1 in the position of the specified pin and 0s everywhere else.
	inline static void getIORegisters(struct IOStruct* io, unsigned char pin)
	{
		io->pinRegister = 0;
		io->portRegister = 0;
		io->ddrRegister = 0;
		io->bitmask = 0;

		if (pin < 8)			// pin 0 = PD0, ..., 7 = PD7
		{
			io->pinRegister = (unsigned char*)&PIND;
			io->portRegister = (unsigned char*)&PORTD;
			io->ddrRegister = (unsigned char*)&DDRD;
			io->bitmask = 1 << pin;
		}

#if defined(_Dcube_SVP) || defined(_Dcube_X2)

		else if (pin < 16)		// pin 8 = PB0, ..., 15 = PB7
		{
			io->pinRegister = (unsigned char*)&PINB;
			io->portRegister = (unsigned char*)&PORTB;
			io->ddrRegister = (unsigned char*)&DDRB;
			io->bitmask = 1 << (pin - 8);
		}
		else if (pin < 24)		// pin 16 = PC0, ..., 23 = PC7
		{
			io->pinRegister = (unsigned char*)&PINC;
			io->portRegister = (unsigned char*)&PORTC;
			io->ddrRegister = (unsigned char*)&DDRC;
			io->bitmask = 1 << (pin - 16);
		}
		else if (pin < 32)		// pin 24 = PA7, ..., 31 = PA0
		{
			io->pinRegister = (unsigned char*)&PINA;
			io->portRegister = (unsigned char*)&PORTA;
			io->ddrRegister = (unsigned char*)&DDRA;
			io->bitmask = 1 << (31 - pin);
		}

#else

		else if (pin < 14)		// pin 8 = PB0, ..., 13 = PB5 (PB6 and PB7 reserved for external clock)
		{
			io->pinRegister = (unsigned char*)&PINB;
			io->portRegister = (unsigned char*)&PORTB;
			io->ddrRegister = (unsigned char*)&DDRB;
			io->bitmask = 1 << (pin - 8);
		}
		else if (pin < 21)		// pin 14 = PC0, ..., 19 = PC5 (PC6 is reset, PC7 doesn't exist)
		{
			io->pinRegister = (unsigned char*)&PINC;
			io->portRegister = (unsigned char*)&PORTC;
			io->ddrRegister = (unsigned char*)&DDRC;
			io->bitmask = 1 << (pin - 14);
		}
#endif
	}


	// low-level method for setting the data direction (i.e. input or output) of an pin or set of pins
	// described by an IOStruct pointer.
	inline static void setDataDirection(struct IOStruct* ioPin, unsigned char val)
	{
		if (val)
			*(ioPin->ddrRegister) |= ioPin->bitmask;
		else
			*(ioPin->ddrRegister) &= ~ioPin->bitmask;
	}


	// low-level method for setting the PORT register value of an pin or set of pins
	// described by an IOStruct pointer.  If the pin is an input, this lets you choose between
	// setting it as high-impedance (val = 0) or enabling the internal pull-up (val = 1).  If the pin is an
	// output, this lets you choose between driving low (val = 0) and driving high (val = 1).
	// NOTE: if val is 0xFF (255), this method will toggle the PORT register pin(s).
	inline static void setOutputValue(struct IOStruct* ioPin, unsigned char val)
	{
		if (val == 0xFF)
			*(ioPin->portRegister) ^= ioPin->bitmask;
		else if (val)
			*(ioPin->portRegister) |= ioPin->bitmask;
		else
			*(ioPin->portRegister) &= ~ioPin->bitmask;
	}


	// low-level method for reading the value of the PIN register for an pin or set of pins
	// described by an IOStruct pointer.
	inline static unsigned char getInputValue(struct IOStruct* ioPin)
	{
		return *(ioPin->pinRegister) & ioPin->bitmask;
	}


	// high-level method for setting the specified pin as an output with the specified output state.
	// An outputState value of 0 will cause the pin to drive low; a value of 1 will cause the pin to 
	// drive high.  A value of 0xFF (255) will toggle the output state of the pin (i.e. high -> low and
	// low -> high).
	inline static void setOutput(unsigned char pin, unsigned char outputState)
	{
		struct IOStruct registers;
		getIORegisters(&registers, pin);
		setOutputValue(&registers, outputState);
		setDataDirection(&registers, 1);
	}


	// high-level method for setting the specified pin as an input with the specified input state.
	// An inputState value of 0 will cause the pin to be a high-impedance input; a value of 1 will enable the 
	// pin's internal pull-up resistor, which weakly pulls it to Vcc.  A value of 0xFF (255) will toggle the
	// input state.
	inline static void setInput(unsigned char pin, unsigned char inputState)
	{
		struct IOStruct registers;
		getIORegisters(&registers, pin);
		setDataDirection(&registers, 0);
		setOutputValue(&registers, inputState);
	}


	// high-level method for reading the input value of the specified pin.  If the voltage on the pin is low,
	// this method will return 0.  Otherwise, it will return a non-zero result that depends on the value of
	// the pin.
	inline static unsigned char isInputHigh(unsigned char pin)
	{
		struct IOStruct registers;
		getIORegisters(&registers, pin);
		return getInputValue(&registers);
	}

};

extern "C" {
#endif // __cplusplus

// gets a structure with pointers to the three digital I/O registers associated
// with the specified pin (DDR, PORT, and PIN) along with a bitmask with a
// 1 in the position of the specified pin and 0s everywhere else.
static inline void get_io_registers(struct IOStruct* io, unsigned char pin)
{
	io->pinRegister = 0;
	io->portRegister = 0;
	io->ddrRegister = 0;
	io->bitmask = 0;

	if (pin < 8)			// pin 0 = PD0, ..., 7 = PD7
	{
		io->pinRegister = (unsigned char*)&PIND;
		io->portRegister = (unsigned char*)&PORTD;
		io->ddrRegister = (unsigned char*)&DDRD;
		io->bitmask = 1 << pin;
	}

#if defined(_Dcube_SVP) || defined(_Dcube_X2)
	else if (pin < 16)		// pin 8 = PB0, ..., 15 = PB7
	{
		io->pinRegister = (unsigned char*)&PINB;
		io->portRegister = (unsigned char*)&PORTB;
		io->ddrRegister = (unsigned char*)&DDRB;
		io->bitmask = 1 << (pin - 8);
	}
	else if (pin < 24)		// pin 16 = PC0, ..., 23 = PC7
	{
		io->pinRegister = (unsigned char*)&PINC;
		io->portRegister = (unsigned char*)&PORTC;
		io->ddrRegister = (unsigned char*)&DDRC;
		io->bitmask = 1 << (pin - 16);
	}
	else if (pin < 32)		// pin 24 = PA7, ..., 31 = PA0
	{
		io->pinRegister = (unsigned char*)&PINA;
		io->portRegister = (unsigned char*)&PORTA;
		io->ddrRegister = (unsigned char*)&DDRA;
		io->bitmask = 1 << (31 - pin);
	}

#else

	else if (pin < 14)		// pin 8 = PB0, ..., 13 = PB5 (PB6 and PB7 reserved for external clock)
	{
		io->pinRegister = (unsigned char*)&PINB;
		io->portRegister = (unsigned char*)&PORTB;
		io->ddrRegister = (unsigned char*)&DDRB;
		io->bitmask = 1 << (pin - 8);
	}
	else if (pin < 21)		// pin 14 = PC0, ..., 19 = PC5 (PC6 is reset, PC7 doesn't exist)
	{
		io->pinRegister = (unsigned char*)&PINC;
		io->portRegister = (unsigned char*)&PORTC;
		io->ddrRegister = (unsigned char*)&DDRC;
		io->bitmask = 1 << (pin - 14);
	}
#endif
}


// low-level method for setting the data direction (i.e. input or output) of an pin or set of pins
// described by an IOStruct pointer.
static inline void set_data_direction(struct IOStruct* ioPin, unsigned char val)
{
	if (val)
		*(ioPin->ddrRegister) |= ioPin->bitmask;
	else
		*(ioPin->ddrRegister) &= ~ioPin->bitmask;
}


// low-level method for setting the PORT register value of an pin or set of pins
// described by an IOStruct pointer.  If the pin is an input, this lets you choose between
// setting it as high-impedance (val = 0) or enabling the internal pull-up (val = 1).  If the pin is an
// output, this lets you choose between driving low (val = 0) and driving high (val = 1).
// NOTE: if val is 0xFF (255), this method will toggle the PORT register pin(s).
static inline void set_digital_output_value(struct IOStruct* ioPin, unsigned char val)
{
	if (val == 0xFF)
		*(ioPin->portRegister) ^= ioPin->bitmask;
	else if (val)
		*(ioPin->portRegister) |= ioPin->bitmask;
	else
		*(ioPin->portRegister) &= ~ioPin->bitmask;
}


// low-level method for reading the value of the PIN register for an pin or set of pins
// described by an IOStruct pointer.
static inline unsigned char get_digital_input_value(struct IOStruct* ioPin)
{
	return *(ioPin->pinRegister) & ioPin->bitmask;
}


// high-level method for setting the specified pin as an output with the specified output state.
// An outputState value of 0 will cause the pin to drive low; a value of 1 will cause the pin to 
// drive high.  A value of 0xFF (255) will toggle the output state of the pin (i.e. high -> low and
// low -> high).
static inline void set_digital_output(unsigned char pin, unsigned char outputState)
{
	struct IOStruct registers;
	get_io_registers(&registers, pin);
	set_digital_output_value(&registers, outputState);
	set_data_direction(&registers, 1);
}


// high-level method for setting the specified pin as an input with the specified input state.
// An inputState value of 0 will cause the pin to be a high-impedance input; a value of 1 will enable the 
// pin's internal pull-up resistor, which weakly pulls it to Vcc.  A value of 0xFF (255) will toggle the
// input state.
static inline void set_digital_input(unsigned char pin, unsigned char inputState)
{
	struct IOStruct registers;
	get_io_registers(&registers, pin);
	set_data_direction(&registers, 0);
	set_digital_output_value(&registers, inputState);
}


// high-level method for reading the input value of the specified pin.  If the voltage on the pin is low,
// this method will return 0.  Otherwise, it will return a non-zero result that depends on the value of
// the pin.
static inline unsigned char is_digital_input_high(unsigned char pin)
{
	struct IOStruct registers;
	get_io_registers(&registers, pin);
	return get_digital_input_value(&registers);
}

#ifdef __cplusplus
}
#endif

#endif

// Local Variables: **
// mode: C++ **
// c-basic-offset: 4 **
// tab-width: 4 **
// indent-tabs-mode: t **
// end: **

Ok, so what is your problem/requirement? Why are you asking if this library can be "converted" for Mega? What you mean with "convert"?
Usually most of the UNO libraries work fine with Mega, so if you try to explain us if you encountered problems a description of the issue could help us, especially because we don't have your library and your Sri Lanka robot...

1 Like

The main requirement is limited number of I/O pins . If we need connect Color sensor and Ultrasonic sensor and servo motor there is no enough pins

A0 to A5 is used for IR sensor
pin 11 /3 a ad 5/ 6 used for motor
pin 12 is used for button
pin 7 and 8 used for LED's
pin 10 used for Buzzer
pin 4 and 9 /7 /8 used for LCD
just pin 2 is free
rx and tx not working with this library

when I select the board as Arduino Mega 2560 then following error is rising

DcubeRobot_MazeSolver:14:10: error: DcubeRobot.h: No such file or directory

 #include <DcubeRobot.h>

          ^~~~~~~~~~~~~~

compilation terminated.

exit status 1
DcubeRobot.h: No such file or directory

the libray have th file also

/*
  DcubeModel.h - Header file for determining which Dcube model is
    being used.

  This header file tests for the __AVR_ATmega* macros and the
        _X2_1284 macro, and uses those to define the _Dcube_* macros,
        which are used when compiliing the library to compile different code
        for the different Dcube models.

  This file is part of the internal implementation of the library; we
  do not recommend using the macros defined here in your code, because
  they may change.  You should instead copy the code in this file in to
  your own header file, and remove the leading underscore from the
  _Dcube_* macro names.
*/

/*
 * Written and modify by PADL Palihawadana, May 1, 2017.
 * Copyright (c) 2012-2022 DCube Robotics. For more information, see
 *
 *   http://www.dcube.lk

 *
 * You may freely modify and share this code, as long as you keep this
 * notice intact (including the link above).  Licensed under the
 * Creative Commons SLR 1.0 license:
 *

 *
 * Disclaimer: To the extent permitted by law, D Cube provides this work
 * without any warranty.  It might be defective, in which case you agree
 * to be responsible for all resulting costs and damages.
 */

#undef _Dcube_X2   // Dcube X2
#undef _Dcube_SVP  // Dcube SVP-324 or 1284
#undef _Dcube_XX4  // Either the X2, SVP-324, or SVP-1284.

#if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(_X2_1284)
 #define _Dcube_X2
#elif defined(__AVR_ATmega324P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega1284PA__)
 #define _Dcube_SVP
#endif

#if defined(_Dcube_SVP) || defined(_Dcube_X2)
  #define _Dcube_XX4
#endif

I don't know either that robot (is it only sold in Sri Lanka?) or its library (without the robot I can't do anything), so I can't help you more thant this.
But I wonder why a change in the library is needed to add some elements: can't you just change your code and "use" the library to do what you intend to do as an extra behaviour for that robot?

1 Like

This is not a robot , I am also don't know about the robot

We are using Arduino Uno and Pololu QTR 8C SENSOR and N20 Motor to build the robot

and this D Cube stranded code is using for programming the robot

if we want connect more sensors and servo motors and I2C device then we are getting struck as limited number of pins with Uno

So you're saying this is not a robot, but you use Arduino, the sensor and the motor, to build the robot. That is (your words) a "line following robot".
It looks like you're saying "this robot is not a robot". A René Magritte fan, huh?... :wink:

Ok, this is my last attempt: why on Earth are you using that weird and uncommon library, made by an unknown Sri Lanka programmer, to build a simple line following robot (having dozens of similar project around)?

1 Like